swift - iOS get heart rate from Apple Watch in near real time -
i need make app records heart rate data in near real time , send data server possible.
first took approach: watch os 2.0 beta: access heart beat rate
in fact working fine. there new heart rate data in healthkit every 5 seconds. have problem can't sync server.
my first approach watch app. watch sending data server. doesn't work because screen turns black on watch, stops sending.
my next approach query healthkit on iphone every 5 seconds new data. works, long app in foreground.
then saw there's kind of background functionality watches healthkit , revokes app background , can something.(enablebackgrounddeliveryfortype) doesn't seem work heart rate (the apple documentation says things steps doesn't work, guess heart rate 1 of those).
i'm stuck now. know how it? need background task executed every 5-10 seconds on iphone. seems impossible
update
as noticed @bootmaker, apple made background mode available hkworkout apps in watchos 3, it's working now. have run hkworkoutsession , keep heartrate delivery in real time when app in background (dark screen on watch)
the closest going while watch app open.
why i'm stating this?
there 2 healthkit's database (one @ iphone , @ apple watch). when sync arbitrary , decided o.s.
the closest going to real time when don't have password locking screen in iphone or apple watch. either way, there's no guarantee sync happen every time new measure added apple watch's healthkit
the way force heart rate sensor working in real time via workouts or observer while apple watch app in foreground.
background delivery not available apple watch apps.
watch os 2 request sensor measure automatically (in background) every 10 minutes minimum.
there's no other workaround, if need real time longer periods, or while user not using app, you need use specialized wearable.
Comments
Post a Comment