CPU Intensive or long task strategy

Hi all,


I'm fairly new to WatckKit; My app captures a bunch of movement related things and when the capture is done It zips the folder containing all the captured data and transfer it using the connectivity framework to the iOS app.


However, sometimes, the watch extension gets killed due to what I suppose being too much CPU or too much CPU time used during the zipping process. The data being zipped is not that big but could be like 1MB. But it seems to take around like 10 seconds to do so.


So my question is "what is the best strategy to handle long running tasks (more than few seconds) and play kind with the system?"


I've seen the ExtensionDelegate handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) but I don't understand what is the use case of this handler and if I could use it to solve my issue.


Any pointers or help appreciated.


Best regards,

Thierry

Replies

Another approach is to transfer the data while it is being collected, or at least in time intervals while it is being collected, rather than waiting until all data collection is over.

Hi PBK, the iOS device may not be nearby. It is not in most of the cases.

There are background methods of transfering info from watch to device that set up their own queue and operate independent of the app at the next opportuinity. (e.g. WCSession)

Problem is that the data is structured much like a bundle (folder, sub folder, file, etc), and it would make it very hard to send it separately. Plus some files are updated during the recording process. I don't think it is a good idea.


Anyways, I made a test Watch App which is supposed to chalenge any CPU watchdog.

After pressing a button in the UI, a task (as a block) is added to an array accessible from the ExtentionDelegate. When applicationWillResignActive() is called I popLast() on the array and execute the task.


To my observation, a task can continue to run without the app being killed by any watchdog. Which is strange because it is killed in the other app which records activity. I made a task to create a 5MB file with random bytes and an other task to zip it ... it takes ages to zip on my Watch series 3 but it is never killed by any watchdog process although the CPU usage is 100% during the whole processing time (around 24 seconds).


So my guess is that the problem I experience in the recording app must come from somewhere else. I will continue investigating.


Best Regards,

Thierry