通过 HRV 跟踪节拍以节拍心率 Apple Watch
Track beat to beat heart rate apple watch through HRV
我正在研究获取单独心跳间隔的心跳间隔的方法。
我戴着 Apple Watch,目前可以导出
<Record type=“HKQuantityTypeIdentifierHeartRateVariabilitySDNN” sourceName=“Apple Watch” sourceVersion=“4.0” device=“<<HKDevice: 0x1c489da10>, name:Apple Watch, manufacturer:Apple, model:Watch, hardware:Watch3,4, software:4.0>” unit=“ms” creationDate=“2017-10-31 13:41:54 +0000" startDate=“2017-10-31 13:40:43 +0000” endDate=“2017-10-31 13:41:54 +0000" value=“92.7156”>
<HeartRateVariabilityMetadataList>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:40:45.22”/>
<InstantaneousBeatsPerMinute bpm=“74" time=“13:40:46.02”/>
<InstantaneousBeatsPerMinute bpm=“71" time=“13:40:46.87”/>
<InstantaneousBeatsPerMinute bpm=“64" time=“13:40:47.81”/>
<InstantaneousBeatsPerMinute bpm=“54" time=“13:40:48.92”/>
<InstantaneousBeatsPerMinute bpm=“57" time=“13:40:49.97”/>
<InstantaneousBeatsPerMinute bpm=“65" time=“13:40:50.90”/>
<InstantaneousBeatsPerMinute bpm=“63" time=“13:40:51.86”/>
<InstantaneousBeatsPerMinute bpm=“60" time=“13:40:52.86”/>
<InstantaneousBeatsPerMinute bpm=“57" time=“13:40:53.92”/>
<InstantaneousBeatsPerMinute bpm=“57" time=“13:40:54.98”/>
<InstantaneousBeatsPerMinute bpm=“61" time=“13:40:55.97”/>
<InstantaneousBeatsPerMinute bpm=“70" time=“13:40:56.83”/>
<InstantaneousBeatsPerMinute bpm=“72" time=“13:40:57.66”/>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:40:58.54”/>
<InstantaneousBeatsPerMinute bpm=“58" time=“13:40:59.58”/>
<InstantaneousBeatsPerMinute bpm=“58" time=“13:41:02.75”/>
<InstantaneousBeatsPerMinute bpm=“63" time=“13:41:03.70”/>
<InstantaneousBeatsPerMinute bpm=“70" time=“13:41:04.56”/>
<InstantaneousBeatsPerMinute bpm=“70" time=“13:41:05.41”/>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:41:13.15”/>
<InstantaneousBeatsPerMinute bpm=“71" time=“13:41:13.99”/>
<InstantaneousBeatsPerMinute bpm=“63" time=“13:41:21.11”/>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:41:21.98”/>
<InstantaneousBeatsPerMinute bpm=“73" time=“13:41:22.79”/>
<InstantaneousBeatsPerMinute bpm=“65" time=“13:41:35.27”/>
<InstantaneousBeatsPerMinute bpm=“67" time=“13:41:36.17”/>
<InstantaneousBeatsPerMinute bpm=“71" time=“13:41:37.01”/>
<InstantaneousBeatsPerMinute bpm=“77" time=“13:41:37.79”/>
<InstantaneousBeatsPerMinute bpm=“79" time=“13:41:38.55”/>
</HeartRateVariabilityMetadataList>
</Record>
但是,当我获取 heartRateVariabilitySDNN
的样本时,我只返回 2 个值。
这是我用来获取示例的代码
let healthStore = HKHealthStore()
var typeHeart = HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)
var startDate = Date() - 7 * 24 * 60 * 60 // start date is a week
var predicate: NSPredicate? = HKQuery.predicateForSamples(withStart: startDate, end: Date(), options: HKQueryOptions.strictEndDate)
let sampleType = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRateVariabilitySDNN)
let sortDescriptor = NSSortDescriptor(key:HKSampleSortIdentifierStartDate, ascending: false)
let sampleQuery = HKSampleQuery(sampleType: sampleType!, predicate: predicate, limit: 30, sortDescriptors: [sortDescriptor])
{ (sampleQuery, results, error ) -> Void in
if(error == nil) {
print(results)
}
}
这是它输出的所有内容:
Optional([92.3536 ms D7627860-F87C-4316-9943-522BC1D6734B "Apple Watch" (4.0), "Watch3,4" (4.0)"Apple Watch" (2017-10-31 13:48:19 +0000 - 2017-10-31 13:53:30 +0000), 92.7156 ms EB0DBCB1-164A-4D50-9103-270F3F9FBCD1 "Apple Watch" (4.0), "Watch3,4" (4.0)"Apple Watch" (2017-10-31 13:40:43 +0000 - 2017-10-31 13:41:54 +0000)])
这基本上是 2 个值:92.7ms 和 92.3ms。这些是手表 'breath' 应用期间 2 次锻炼的平均值。
有谁知道我如何获得 InstantaneousBeatsPerMinute
and/or HRV 元数据?
编辑:似乎发生了一些有趣的事情,输出值看起来非常像 XML.
中 Record
类型的打印语句
如果你想获得瞬时心率,你的应用应该启动一个 HKWorkoutSession。
self.workoutSession = HKWorkoutSession(activityType: .Running, locationType: .Indoor)
self.workoutSession!.delegate = self;
self.healthStore.startWorkoutSession(self.workoutSession!)
Then, you can start a streaming query from HKHealthKit to give you updates as HealthKit receives them:
let distanceType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)
let predicate = HKQuery.predicateForSamplesWithStartDate(workoutStartDate, endDate: nil, options: .None)
let distanceQuery = HKAnchoredObjectQuery(type: distanceType!, predicate: predicate, anchor: 0, limit: 0) { (query, samples, deletedObjects, anchor, error) -> Void in
// Handle when the query first returns results
// TODO: do whatever you want with samples (note you are not on the main thread)
}
distanceQuery.updateHandler = { (query, samples, deletedObjects, anchor, error) -> Void in
// Handle update notifications after the query has initially run
}
self.healthStore.executeQuery(distanceQuery)
在向 Apple 提交技术支持事件 (TSI) 后,他们表示目前无法执行此操作。
Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.
If you would like for Apple to consider adding support for such features in the future, please submit an enhancement request via the Bug Reporter tool at https://developer.apple.com/bug-reporting/.
如果您想看到此功能,请提交错误报告!
在iOS13 Apple发布了新的Heartbeat系列API。您可以在此处找到更多详细信息:
https://developer.apple.com/documentation/healthkit/samples/reading_and_writing_healthkit_series_data
https://developer.apple.com/documentation/healthkit/hkheartbeatseriessample
https://developer.apple.com/documentation/healthkit/hkheartbeatseriesquery
这个相关的 WWDC 视频 session 对于理解这个新的 API 非常有用:
https://developer.apple.com/videos/play/wwdc2019/218
我正在研究获取单独心跳间隔的心跳间隔的方法。
我戴着 Apple Watch,目前可以导出
<Record type=“HKQuantityTypeIdentifierHeartRateVariabilitySDNN” sourceName=“Apple Watch” sourceVersion=“4.0” device=“<<HKDevice: 0x1c489da10>, name:Apple Watch, manufacturer:Apple, model:Watch, hardware:Watch3,4, software:4.0>” unit=“ms” creationDate=“2017-10-31 13:41:54 +0000" startDate=“2017-10-31 13:40:43 +0000” endDate=“2017-10-31 13:41:54 +0000" value=“92.7156”>
<HeartRateVariabilityMetadataList>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:40:45.22”/>
<InstantaneousBeatsPerMinute bpm=“74" time=“13:40:46.02”/>
<InstantaneousBeatsPerMinute bpm=“71" time=“13:40:46.87”/>
<InstantaneousBeatsPerMinute bpm=“64" time=“13:40:47.81”/>
<InstantaneousBeatsPerMinute bpm=“54" time=“13:40:48.92”/>
<InstantaneousBeatsPerMinute bpm=“57" time=“13:40:49.97”/>
<InstantaneousBeatsPerMinute bpm=“65" time=“13:40:50.90”/>
<InstantaneousBeatsPerMinute bpm=“63" time=“13:40:51.86”/>
<InstantaneousBeatsPerMinute bpm=“60" time=“13:40:52.86”/>
<InstantaneousBeatsPerMinute bpm=“57" time=“13:40:53.92”/>
<InstantaneousBeatsPerMinute bpm=“57" time=“13:40:54.98”/>
<InstantaneousBeatsPerMinute bpm=“61" time=“13:40:55.97”/>
<InstantaneousBeatsPerMinute bpm=“70" time=“13:40:56.83”/>
<InstantaneousBeatsPerMinute bpm=“72" time=“13:40:57.66”/>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:40:58.54”/>
<InstantaneousBeatsPerMinute bpm=“58" time=“13:40:59.58”/>
<InstantaneousBeatsPerMinute bpm=“58" time=“13:41:02.75”/>
<InstantaneousBeatsPerMinute bpm=“63" time=“13:41:03.70”/>
<InstantaneousBeatsPerMinute bpm=“70" time=“13:41:04.56”/>
<InstantaneousBeatsPerMinute bpm=“70" time=“13:41:05.41”/>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:41:13.15”/>
<InstantaneousBeatsPerMinute bpm=“71" time=“13:41:13.99”/>
<InstantaneousBeatsPerMinute bpm=“63" time=“13:41:21.11”/>
<InstantaneousBeatsPerMinute bpm=“69" time=“13:41:21.98”/>
<InstantaneousBeatsPerMinute bpm=“73" time=“13:41:22.79”/>
<InstantaneousBeatsPerMinute bpm=“65" time=“13:41:35.27”/>
<InstantaneousBeatsPerMinute bpm=“67" time=“13:41:36.17”/>
<InstantaneousBeatsPerMinute bpm=“71" time=“13:41:37.01”/>
<InstantaneousBeatsPerMinute bpm=“77" time=“13:41:37.79”/>
<InstantaneousBeatsPerMinute bpm=“79" time=“13:41:38.55”/>
</HeartRateVariabilityMetadataList>
</Record>
但是,当我获取 heartRateVariabilitySDNN
的样本时,我只返回 2 个值。
这是我用来获取示例的代码
let healthStore = HKHealthStore()
var typeHeart = HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)
var startDate = Date() - 7 * 24 * 60 * 60 // start date is a week
var predicate: NSPredicate? = HKQuery.predicateForSamples(withStart: startDate, end: Date(), options: HKQueryOptions.strictEndDate)
let sampleType = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRateVariabilitySDNN)
let sortDescriptor = NSSortDescriptor(key:HKSampleSortIdentifierStartDate, ascending: false)
let sampleQuery = HKSampleQuery(sampleType: sampleType!, predicate: predicate, limit: 30, sortDescriptors: [sortDescriptor])
{ (sampleQuery, results, error ) -> Void in
if(error == nil) {
print(results)
}
}
这是它输出的所有内容:
Optional([92.3536 ms D7627860-F87C-4316-9943-522BC1D6734B "Apple Watch" (4.0), "Watch3,4" (4.0)"Apple Watch" (2017-10-31 13:48:19 +0000 - 2017-10-31 13:53:30 +0000), 92.7156 ms EB0DBCB1-164A-4D50-9103-270F3F9FBCD1 "Apple Watch" (4.0), "Watch3,4" (4.0)"Apple Watch" (2017-10-31 13:40:43 +0000 - 2017-10-31 13:41:54 +0000)])
这基本上是 2 个值:92.7ms 和 92.3ms。这些是手表 'breath' 应用期间 2 次锻炼的平均值。
有谁知道我如何获得 InstantaneousBeatsPerMinute
and/or HRV 元数据?
编辑:似乎发生了一些有趣的事情,输出值看起来非常像 XML.
中Record
类型的打印语句
如果你想获得瞬时心率,你的应用应该启动一个 HKWorkoutSession。
self.workoutSession = HKWorkoutSession(activityType: .Running, locationType: .Indoor)
self.workoutSession!.delegate = self;
self.healthStore.startWorkoutSession(self.workoutSession!)
Then, you can start a streaming query from HKHealthKit to give you updates as HealthKit receives them:
let distanceType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)
let predicate = HKQuery.predicateForSamplesWithStartDate(workoutStartDate, endDate: nil, options: .None)
let distanceQuery = HKAnchoredObjectQuery(type: distanceType!, predicate: predicate, anchor: 0, limit: 0) { (query, samples, deletedObjects, anchor, error) -> Void in
// Handle when the query first returns results
// TODO: do whatever you want with samples (note you are not on the main thread)
}
distanceQuery.updateHandler = { (query, samples, deletedObjects, anchor, error) -> Void in
// Handle update notifications after the query has initially run
}
self.healthStore.executeQuery(distanceQuery)
在向 Apple 提交技术支持事件 (TSI) 后,他们表示目前无法执行此操作。
Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.
If you would like for Apple to consider adding support for such features in the future, please submit an enhancement request via the Bug Reporter tool at https://developer.apple.com/bug-reporting/.
如果您想看到此功能,请提交错误报告!
在iOS13 Apple发布了新的Heartbeat系列API。您可以在此处找到更多详细信息:
https://developer.apple.com/documentation/healthkit/samples/reading_and_writing_healthkit_series_data https://developer.apple.com/documentation/healthkit/hkheartbeatseriessample https://developer.apple.com/documentation/healthkit/hkheartbeatseriesquery
这个相关的 WWDC 视频 session 对于理解这个新的 API 非常有用: https://developer.apple.com/videos/play/wwdc2019/218