iOS get heart rate from Apple Watch in near real time
<p>I need to make an app that records heart rate data in near real time and send this data to a server as soon as possible.</p>

<p>First I took this approach: <a href="https://stackoverflow.com/questions/30776331/watch-os-2-0-beta-access-heart-beat-rate">Watch os 2.0 beta: access heart beat rate</a></p>

<p>In fact it is working fine. There is new heart rate data in the HealthKit every five seconds. But now I have the problem that I can't sync that with a server.</p>

<p>My first approach was the Watch app. The watch was sending data to a server. That doesn't work because as soon as the screen turns black on the watch, it stops sending. </p>

<p>My next approach was to query the HealthKit on the iPhone every five seconds for new data. This works, as long as the app is in foreground.</p>

<p>Then I saw that there's some kind of background functionality that watches the HealthKit itself and revokes the app from background and you can do something.(enableBackgroundDeliveryForType)  This doesn't seem to work for heart rate (the Apple Documentation says for things like steps this doesn't work, I guess heart rate is one of those). </p>

<p>I'm stuck now. Do you know how to it? I would need some background task that is executed every 5-10 seconds on the iPhone. That seems to be impossible</p>