1)为什么我没有在println函数的控制台中获得任何输出? (我运行代码时没有出现任何错误。)
func perfromQueryForHRSamples() {
let startDate = NSDate(timeIntervalSinceNow: -30*24*60*60)
let endDate = NSDate()
let heartRateSample = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)
let predicate = HKQuery.predicateForSamplesWithStartDate(startDate, endDate: endDate, options: .None)
let sampleQuery = HKSampleQuery(sampleType: HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate),
predicate: predicate,
limit: 100,
sortDescriptors: nil,
resultsHandler: { (query, results, error) in
if error != nil {
println("There was an error: \(error)")
}
for result in results as [HKQuantitySample]! {
let count = results.count
println("Success \(count)")
}
})
self.healthStore.executeQuery(sampleQuery)
}
答案 0 :(得分:-1)
因为未在viewDidLoad中调用该函数
override func viewDidLoad() {
super.viewDidLoad()
requestAuthorisationForHealthStore()
perfromQueryForHRSamples()
}