它应该放在AppDelegate.swift文件中吗?
我看了苹果的文档,看到了他们的例子:
let sampleType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)
let query = HKObserverQuery(sampleType: sampleType, predicate: nil) {
query, completionHandler, error in
if error != nil {
// Perform Proper Error Handling Here...
println("*** An error occured while setting up the stepCount observer. \(error.localizedDescription) ***")
abort()
}
// Take whatever steps are necessary to update your app's data and UI
// This may involve executing other queries
self.updateDailyStepCount()
}
healthStore.executeQuery(query)不是很清楚。
他们还引用了具有以下声明的initWithSampleType:predicate:updateHandler,但是如果我遵循上面的格式,我需要使用它吗?
init!(sampleType sampleType: HKSampleType!,
predicate predicate: NSPredicate!,
updateHandler updateHandler: ((HKObserverQuery!,
HKObserverQueryCompletionHandler!,
NSError!) -> Void)!)发布于 2015-03-27 18:32:39
我建议您为healthKit创建一个单例,您不希望将所有代码都放在AppDelegate上
示例http://www.raywenderlich.com/86336/ios-8-healthkit-swift-getting-started
https://stackoverflow.com/questions/28102752
复制相似问题