首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >enableBackgroundDelivery Health iOS15不能正常工作

enableBackgroundDelivery Health iOS15不能正常工作
EN

Stack Overflow用户
提问于 2021-09-26 05:41:50
回答 1查看 989关注 0票数 4

我在做健康用品。在下面的代码正确工作之前,我是每小时获得生命体征,但在这个最新版本中,我不会每小时获得任何生命周期事件。

我在iOS15中面临一个问题,在每小时的事件中没有得到任何事件。有人能帮我吗?根据苹果文档https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddelivery,我已经启用了XCode13中的权限,但我仍然面临着这个问题。

这是我的密码。(iOS15之前的工作代码)

代码语言:javascript
复制
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()
 }
EN

回答 1

Stack Overflow用户

发布于 2021-09-26 19:21:05

检查是否为您的应用程序启用后台应用程序刷新。如果是这样,而且您还在遇到这个问题,请向Apple提交一份反馈助理报告,并提供示例代码和系统诊断。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69332173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档