几天来,我一直在使用对这个错误的引用,试图找出解决方案:
[query] Error activating query: Error Domain=com.apple.healthkit Code=5 "Authorization not determined" UserInfo={NSLocalizedDescription=Authorization not determined}
我一直在使用 HealthKit 成功检索睡眠数据,但现在我需要检索活动数据。我用这个功能设置了 HealthKit:
let typesToRead = Set([
HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.sleepAnalysis)!,
HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.appleStandHour)!,
HKObjectType.characteristicType(forIdentifier: HKCharacteristicTypeIdentifier.dateOfBirth)!,
HKObjectType.characteristicType(forIdentifier: HKCharacteristicTypeIdentifier.bloodType)!,
HKObjectType.characteristicType(forIdentifier: HKCharacteristicTypeIdentifier.biologicalSex)!,
HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.height)!,
HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bodyMass)!,
HKObjectType.workoutType(),
HKObjectType.activitySummaryType()
])
self.healthStore.requestAuthorization(toShare: nil, read: typesToRead) { (sucess, error) -> Void in
if sucess == false {
NSLog("Error...")
}
}
然后我创建我的查询,如:
let query = HKSampleQuery(sampleType: distanceType, predicate: nil, limit: 0, sortDescriptors: [startDateSort]) {
(sampleQuery, results, error) -> Void in
if let result = results {
for item in result {
if let sample = item as? HKQuantitySample {
self.workOutSamples.append(sample)
}
}
print(self.workOutSamples)
}
}
healthStore.execute(query)
我已将Privacy - Health Update Usage Description
and添加Privacy - Health Share Usage Description
到 info.plist 并且我的应用程序的功能包括 HealthKit 已成功打开。