无需在手表上创建应用程序即可在 Apple Watch Series 3 中读取心率 [英] Read Heart Rate in Apple Watch Series 3 without creating an app on the Watch

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

问题描述

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

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 将其所有记录的心率数据(佩戴时每五分钟自动采样一次,在锻炼期间更频繁地采样)到伴侣上的 HealthKit 商店苹果手机.

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.

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

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. 在 Xcode 的功能"窗格(应用目标设置的一部分)中为 HealthKit 支持设置您的项目.

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

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

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

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

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)

  • 在完成处理程序报告成功后,使用 HKSampleQuery 搜索最近的心率样本、指定时间范围内的一组心率样本等(或其他HKQuery 子类,例如随时间变化的平均心率等)

  • 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.)

    <小时>

    如果您想要的是一种从 iOS 应用程序立即"读取用户当前心率的方法,而无需创建配套的 watchOS 应用程序……不,没有办法做到这一点.


    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 中读取心率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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