I need to make an application that records heart rate data in the near real time and sends this data to the server as soon as possible.
At first I took this approach: Watch os 2.0 beta: access your heart rate
It actually works fine. HealthKit introduces new heart rate data every five seconds. But now I have a problem that I cannot synchronize this with the server.
My first approach is the Watch app. The clock sent data to the server. This does not work, because as soon as the screen turns black on the watch, it stops sending.
My next approach was to request HealthKit on the iPhone every five seconds for new data. This works if the application is in the foreground.
Then I saw that there is some kind of background functionality that monitors HealthKit itself and cancels the application from the background, and you can do something. (enableBackgroundDeliveryForType) This doesn't seem to work for heart rate (Apple Documentation talks about things like steps, it doesn't work, I think heart rate is one of those).
I'm stuck now. Do you know how to do this? I will need a background task that runs every 5-10 seconds on an iPhone. It seems impossible
source share