HKHealthStore startWatchAppWithWorkoutConfiguration:completion: not always received until watch woken

We're using the HKHealthStore startWatchAppWithWorkoutConfiguration:completion: method to start a workout on the Apple Watch in response to user interaction on the iPhone, but we are finding that the ExtensionDelegate handleWorkoutConfiguration: method is not always called in a timely way - for example, the method may not execute until the watch is explicitly woken, 30-60 seconds after the initial call on the iPhone. This happens fairly frequently, but there doesn't seem to be a pattern to it.


Because it hasn't completely failed, our completion block is not executed on the phone, so we have no way to know that this is occurring, other than the fact that the workout doesn't start.


Does anyone have any insight? Our Watch app is already running on the Watch when we see this problem - if the app needs launching then it seems to be OK.

Replies

An update: the request is in fact being received, but it appears that the Watch app isn’t getting enough background time to actually get the workout started, even though the call to the HKHealthStore has been made.


Is it possible there are some background threads started by startWorkoutSession: that are not managing to finish executing before the app loses CPU time? We use the workout background mode, so once the workout does actually start everything is OK.

Not sure how you figured out that it was a time allocation issue, but that was a big help. My team ran into this same problem, but thanks to you I was able to come up with a (hacky) solution. Seems like when the watch is locked and inactive (your app is not the active app, and the watch screen is black) the watch doesn't give the app enough time to even make it to the handle() method. For some reason though, it seems like this process continues where it left off on subsquent calls to startWatchApp, which in my case meant that calling startWatchApp a second time would result in handle being called. So, my hacky solution is to call startWatchApp and then call it again in the completion block.

Thanks for posting - that's pretty much what we ended up doing.