Read Heart Rate in Apple Watch Series 3 without creating an app on the Watch

£可爱£侵袭症+ 提交于 2019-12-24 19:36:53

问题


Is it possible to read/sync the Heart Rate data from Apple watch series 3 without creating a watch app? I want my iPhone app to read data directly from the Apple Watch without having to create an app for the watch too.


回答1:


Apple Watch syncs all of its recorded heart rate data (automatically sampled every five minutes while wearing, and more frequently during workout sessions) to the HealthKit store on the companion iPhone.

So you can create an iOS app that (with the user's permission) reads the stored heart rate data using HealthKit. The gist of it:

  1. Set up your project for HealthKit support in Xcode's Capabilities pane (part of your app target settings).

  2. Check for HealthKit availability on the device (HKHealthStore.isHealthDataAvailable()) and create an HKHealthStore object.

  3. Verify that you have user permission to access heart rate data:

    let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate)!
    healthStore.requestAuthorization(toShare: nil, read: [heartRateType], completion: myHandler)
    
  4. After that completion handler reports success, use HKSampleQuery to search for the most recent heart rate sample, a set of heart rate samples within a specified time frame, etc. (Or other HKQuery subclasses for things like average heart rate over time, etc.)


If instead what you're asking is for a way to read the user's current heart rate "right now" from an iOS app, without creating a companion watchOS app... no, there's not a way to do that.



来源:https://stackoverflow.com/questions/48099856/read-heart-rate-in-apple-watch-series-3-without-creating-an-app-on-the-watch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!