它应该放在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)!)
答案 0 :(得分:0)
我建议您为healthKit创建一个单例,您不希望将所有代码放在AppDelegate上
实施例 http://www.raywenderlich.com/86336/ios-8-healthkit-swift-getting-started