我已经使用此错误的引用了几天,现在试图找出解决方案:
[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
和Privacy - Health Share Usage Description
添加到Info.plist,我的应用程序的功能包括HealthKit成功打开了。
将 HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!
添加到tatpestoread。我的帖子没有显示我使用错误的类型:创建distanceType
时的quantityType
。