几天来我一直在使用对此错误的引用,现在试图找出解决方案:
[query] 激活查询时出错:Error Domain=com.apple.healthkit Code=5“未确定授权”UserInfo={NSLocalizedDescription=未确定授权}
我一直在使用 HealthKit 成功检索 sleep 数据,但现在我需要检索事件数据。我用这个函数设置了 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)
我已将隐私 - 健康更新使用说明
和隐私 - 健康共享使用说明
添加到 info.plist 并且我的应用程序的功能包括已成功启用 HealthKit。
最佳答案
向 typesToRead 添加了 HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!
。我的帖子没有显示我在创建 distanceType
时使用了错误的类型:quantityType
。
关于ios - 使用 HealthKit 检索 SleepAnalysis 后,我仍然收到此授权未确定错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44417472/