私は今のソリューションを把握しようと数日間、このエラーへの参照を使用してきた:SleepAnalysisを取得するためにHealthKitを使用した後、私はまだ、この認証を取得しないと判断エラー
[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...")
}
}
その後、私はのように私のクエリを作成します。私は、Info.plistのためにPrivacy - Health Update Usage Description
とPrivacy - Health Share Usage Description
を追加し、私のアプリの機能はHealthKitが正常にオンに含ま
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)
。