0

几天来,我一直在使用对这个错误的引用,试图找出解决方案:

[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 Descriptionand添加Privacy - Health Share Usage Description到 info.plist 并且我的应用程序的功能包括 HealthKit 已成功打开。

4

1 回答 1

0

添加HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!到 typesToRead。我的帖子没有显示我使用了错误的类型:quantityType创建distanceType.

于 2017-06-07T16:33:27.633 回答