0

I am using SwiftUI to develop a WatchOS application for activity pacing; the main feature in question is monitoring the users' heart rate and sending a notification when it exceeds a threshold they have defined. Currently, I am using WKExtendedRuntimeSession and background delivery for this but from everything I can gather from the documentation, it seems there is no way to guarantee that the app will actually keep running in the background continuously.

I am also monitoring for when the sessions expire and I am restarting them, however I am wondering if there is a better approach than this as my use case seems to be quite simple yet this implementation is very complicated and has a lot of moving parts.

2
  • From my watch usage experience, it seems that if your app start a workout, it should have more privileges, maybe including background. An other hack I saw is activating microphone to keep it working in background, this app is using it to deliver vibrations regularly. Commented Aug 6, 2024 at 5:23
  • Don't have an Apple Watch anymore, but I used to just leave the heart-rate monitoring page on when I want to continuously monitor while I'm on the treadmill or cycling. It works, but drains the battery, as screen needs to be on all the time too. Commented Aug 11, 2024 at 20:40

1 Answer 1

1

In order to do that, you would use Healthkit for Heart Rate monitoring. Although you have to request user authorization first. Then you would need to set up a HKObserverQuery to monitor heart rate changes. This query will be notified when new heart rate data is available. Then you would need to import UserNotifications to alert the user when a heart rate is exceeded. You might also use WatchConnectivity to synchronize the user and phone.

Apps can certainly run in the background and alert users, but they need to be started up first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.