|
Hi everybody, I am trying to use a timer for an exercise app on Apple Watch (timer used for resting time after an exercise) but this timer stops when the watch goes in sleep mode (triggered by a wrist down). This is very unpractical as the user does the wrist down naturally during resting and the timer is stopped. I am using a basic timer with publish and on receive:
but it does not work whenever the user does a wrist down. Can you please let me know how should I use the timer in order to work even in sleep mode? I see that the Apple Exercise app timer works even in sleep mode. Therefore, that should be doable. Thank you in advance for your help |
|
Hi, in general these timers are implemented in a way that you save the info that timer is running (+ start time) and then when app becomes active you can calculate the real elapsed time and update the UI. |
|
Thanks for the answer. The only issue with this solution is when the timer goes to 0 and the watch is in sleep mode. I would like to give the user some haptic feedback when the timer goes to 0 (the resting time is over, it's time to go to the next exercise) whether the watch is active or in sleep mode. The apple exercise app seems to be working fine in sleep mode (timer + heartbeat recording are still running). Thus, I'd like to know how can I run some minimal code during sleep mode. Thank you in advance for your feeback |
|
Could you make the cool down a sepearte workout activity or a mindful activity? These are a few valid activities allowed in the background. Or schedule a local notification nSecs when the cool down should end? |
|
Thanks, I think the notification will be the best approch. For the count down, I used this code and it solves the problem perfectly. Thanks
For the notification, I used a simple test notification with a 5 second timer. It works perfectly when I quit the app before the 5 sec countdown, but not when I stay in the app with a wrist down (to put the watch in sleep mode)
Should I use something different in order to make this notification work even if I stay in the app in sleep mode? I am not too familiar with the UserNotifications framework :( |
|
@alexismoulin You can use Look at an example "How to make Apple Watch Haptic Engine continue playing in background" article. |
|
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.