我在做健康用品。在下面的代码正确工作之前,我是每小时获得生命体征,但在这个最新版本中,我不会每小时获得任何生命周期事件。
我在iOS15中面临一个问题,在每小时的事件中没有得到任何事件。有人能帮我吗?根据苹果文档https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddelivery,我已经启用了XCode13中的权限,但我仍然面临着这个问题。
这是我的密码。(iOS15之前的工作代码)
private func startObservingStepCountChanges() {
let sampleType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
let query: HKObserverQuery = HKObserverQuery(sampleType: sampleType!, predicate: nil, updateHandler: self.stepChangeHandler)
healthKitStore.execute(query)
healthKitStore.enableBackgroundDelivery(for: sampleType!, frequency: .hourly, withCompletion: {(succeeded: Bool, error: Error!) in
if succeeded{
print("Enabled background delivery of stepcount changes")
} else {
if let theError = error{
print("Failed to enable background delivery of stepcount changes. ")
print("Error = \(theError)")
}
}
} as (Bool, Error?) -> Void)
}
private func stepChangeHandler(query: HKObserverQuery!, completionHandler: HKObserverQueryCompletionHandler!, error: Error!) {
// Flag to check the background handler is working or not
print("Backgound Mode activated")
fireTestPush()
completionHandler()
}发布于 2021-09-26 19:21:05
检查是否为您的应用程序启用后台应用程序刷新。如果是这样,而且您还在遇到这个问题,请向Apple提交一份反馈助理报告,并提供示例代码和系统诊断。
https://stackoverflow.com/questions/69332173
复制相似问题