在Apple Watch Series 3上读取心率,而无需在Watch上创建应用 [英] Read Heart Rate in Apple Watch Series 3 without creating an app on the Watch

查看:424
本文介绍了在Apple Watch Series 3上读取心率,而无需在Watch上创建应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不创建手表应用程序的情况下从Apple Watch Series 3读取/同步心率数据? 我希望我的iPhone应用程序直接从Apple Watch读取数据,而不必也为该手表创建应用程序.

解决方案

Apple Watch将所有记录的心率数据(佩戴时每五分钟自动采样一次,锻炼期间更频繁地自动采样)同步到同伴上的HealthKit商店苹果手机.

因此,您可以创建一个iOS应用,该应用(在用户许可下)使用HealthKit读取存储的心率数据.要点:

  1. 在Xcode的功能"窗格(您的应用程序目标设置的一部分)中为HealthKit支持设置项目.

  2. 检查设备(HKHealthStore.isHealthDataAvailable())上的HealthKit可用性,并创建一个 HKHealthStore 对象.

  3. 验证您是否具有访问心率数据的用户权限:

    let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate)!
    healthStore.requestAuthorization(toShare: nil, read: [heartRateType], completion: myHandler)
    

  4. 该完成处理程序报告成功后,使用 HKSampleQuery 进行操作搜索最新的心率样本,指定时间范围内的一组心率样本,等等.(或其他

    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.

    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.

    这篇关于在Apple Watch Series 3上读取心率,而无需在Watch上创建应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆