使用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...")
        }
    }

然后我创建我的查询:

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 DescriptionPrivacy - Health Share Usage Description添加到Info.plist,我的应用程序的功能包括HealthKit成功打开了。

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

相关内容

  • 没有找到相关文章

最新更新