ios - HKAnchoredObejctQuery 不返回新结果+不一致
问题描述
这是我用来构建和执行查询的代码,它会在加载视图时以及每当按下视图上的按钮时触发。
private func startHeartRateQuery(quantityTypeIdentifier: HKQuantityTypeIdentifier)
{
var myAnchor = lastAnchor
let query = HKAnchoredObjectQuery(type: HKObjectType.quantityType(forIdentifier: quantityTypeIdentifier)!,
predicate: pred, anchor: myAnchor,
limit: HKObjectQueryNoLimit)
{ (query, samplesOrNil, deletedObjectsOrNil, newAnchor, errorOrNil)
in guard let samples = samplesOrNil as? [HKQuantitySample], let deletedObjects = deletedObjectsOrNil else
{
//error
print("something bad happened")
return
}
myAnchor = newAnchor!
self.process(samples, type: quantityTypeIdentifier)
DispatchQueue.main.async {
updateStatus()
}
}
query.updateHandler = { (query, samplesOrNil, deletedObjectsOrNil, newAnchor, errorOrNil) in
guard let samples = samplesOrNil as? [HKQuantitySample], let deletedObjects = deletedObjectsOrNil else {
// Properly handle the error.
print("something bad happened in the update handler")
return
}
myAnchor = newAnchor!
print("doing something here in update handler")
self.process(samples, type: quantityTypeIdentifier)
DispatchQueue.main.async {
updateStatus()
}
}
// 5
healthStore.execute(query)
}
但是,当按下按钮时,我没有收到来自设备的更新心率,如下所示:
126 2021-10-26 22:37:46 +0000
processing...
126 2021-10-26 22:37:46 +0000
processing...
126 2021-10-26 22:37:46 +0000
processing...
126 2021-10-26 22:37:46 +0000
processing...
126 2021-10-26 22:37:46 +0000
processing...
任何有关获得心率查询一致更新的帮助表示赞赏(目标是获取自上次在应用程序中更新以来的所有最新心率)。
编辑:在相当长的一段时间过去后,我还看到了一些奇怪的行为,它延伸到过去并从那里提取数据以及一些新数据。我根本不理解这个查询的行为,因为它现在不一致。
doing something here in update handler
75 2021-10-26 22:32:07 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
85 2021-10-26 22:38:39 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
85 2021-10-26 22:38:39 +0000
83 2021-10-26 22:38:44 +0000
83 2021-10-26 22:38:49 +0000
84 2021-10-26 22:38:50 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
85 2021-10-26 22:38:39 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
processing...
doing something here in update handler
75 2021-10-26 22:32:07 +0000
解决方案
推荐阅读
- python - Pandas DataFrame 在“Value2”中的“Value1”上加入/合并
- reactjs - 如何获取选中的索引
- python - 将任何输入数字乘以下一个整数的方法
- python - 在 Azure Python SDK 中创建 NIC 时如何指定网络安全组
- textfield - SwiftUI TextField 光标颜色
- delphi - 如何将流参数发送到 EMSDataSetResource
- python - PyQt5 组合框清除然后 addItems 崩溃 Python
- swiftui - SwiftUI:在 PageViewController 上呈现模式
- jquery - 将 css 附加到 head 时,出现错误。怎么修
- django - 如何在Django中将一个表的行链接到另一个表的行?