WatchOS2 - NSTimer in background

Hello,


I'm running into an issue where I cant keep the timer running on background (ie when the watch goes in stand-by etc)


On simulator:

The behaviour is as expect, the timer continues in the background and everything is textbook perfect


On Apple Watch:

This is based on feedback and demonstrations. The timer freezes and continues when app is in foreground.


So I'm wondering why the discrepency and how can I ensure the timer runs when the watch goes to sleep?

Yes, workoutSession only keeps your app active on screen (no watch face after 30 seconds) and collects data from sensors.

While in background, the watch app is suspended and its code is not executed.

Ok clear!! So with my currrent implementation(as per your suggestion) I use an NSdate to track the time lapsed and reset the timer when the watch is "on". Thats all good and all but if the watch is locked, I can't give any haptic feedback, even with a workoutSession active.


Any thoughts?

See the other post in this forum on a similar bug in WatchOS and a work-around

Can you post a link?

This issue is unrelated and has to do with a specific case where the wrist is lowered and raised really quickly. I already implement an NSTimer after checking my NSDate and resetting the timer to the correct part. The problem is when the watch is sleep (even with a workoutSession active) I can't give and haptic feedback.


This is because there can't be any background tasks.

I think you can't.

You should send a notification in order to give a feedback while in background.

Yea that makese sense if you can't run any code in the background (even when wrkout session is active)


By the way, why do people refer to app activie in background as foreground? Its only foreground if its on screen, not when locked.

You're correct. 😀

I see.. So back to the notification thing. So the Apple Watch is suppose to post a notification to itself?

I doubt WatchKit can post a notification. You should do it through your iOS app.

I see. I hope Apple fixes ttheir no code execution policy when a workoutSession is active.

acegreen,

did you ever figure out how to get around the issue of firing haptic feedback while in a workoutsession?

As you may now, its now possible even for watchOS 2 apparently.

Hey all, I made events fire in the bacgkround thanks to the answer Mrsantams answer here; https://stackoverflow.com/questions/31707974/watchos-2-haptic-feedback-in-background


Maybe this is new in the new APIs which is why it's working. Anyway, I had the same problem with the NSTimer selector function not firing in the background. Once I updated my Capabilities of my Watch Extension these started firing. In my case, this provides haptic feedback in the background based on intervals determined by an NSTimer.


Hope this helps someone. Cheers.

WatchOS2 - NSTimer in background
 
 
Q