How to keep an Apple Watch app running when watch is charging

620 Views Asked by At

I'm making an Apple Watch app to record user acceleration. Currently, the user configures the session length to record for, and using a HKWorkoutSession, the app records acceleration for that time period.

My issue: I want the user to be able to remove their watch and charge it in the middle of a long session. In debugging the watch on Xcode, when I place the watch on the charger, I get the messages:

Message from debugger: Terminated due to signal 9
Program ended with exit code: 0

And the debugger is no longer connected. After a short while, the HKWorkoutSession ends as well, and the app is no longer recording.

Looking at https://medium.com/@gohnjanotis/apple-watch-battery-level-charging-notifications-eb7d0797a4d8, and the statement "While on the charger it seems these background refresh tasks are paused altogether.", I'm not sure I understand the Watch app life cycle fully. Is it even possible to have an app continue running in the background when the watch is set to charge?

Would appreciate any advice on this. Cheers.

1

There are 1 best solutions below

0
On

It's unlikely that watchOS background tasks work similarly to iOS, where an iPhone can for example do expensive Photos operations when the device is charging. Why not pause and resume the workout session?

The "Recover from Crashes" at the bottom of Running Workout Sessions | Apple Developer Documentation might be helpful.