gpt4 book ai didi

ios - HKObserverQuery 后台传递在调用completionHandler 后停止工作

转载 作者:行者123 更新时间:2023-11-30 12:06:02 31 4
gpt4 key购买 nike

因此,根据 Apple 的说法,在添加到 HK 的数据触发 updateHandler 后,我需要调用 HKObserverQueryCompletionHandler

但是一旦我调用completionHandler,观察者查询就会停止在后台提供任何更多更新..

这是我的代码:

guard let sampleType = sample as? HKQuantityType else { return nil }

let query = HKObserverQuery(sampleType: sampleType, predicate: nil, updateHandler: { query, completionHandler, error in

completionHandler()

IamExecutingHKStatisticsCollectionQueryHere()
})

healthStore?.execute(query)
healthStore?.enableBackgroundDelivery(for: sampleType, frequency: .hourly, withCompletion: { success, error in

})

如果我不调用completionHandler,一切正常,但我从未测试过很长时间..

最佳答案

调用completionHandler()表示您已完成新数据的处理。仅在处理完响应 updateHandler 调用而执行的查询结果后才调用它。如果您现在就调用 completionHandler(),系统将在您有机会处理数据之前停止在后台运行您的应用。

关于ios - HKObserverQuery 后台传递在调用completionHandler 后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46669260/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com