2017-06-07 38 views
0

我一直在使用引用此錯誤了幾天,現在試圖找出一個解決方案:使用HealthKit檢索SleepAnalysis後,我仍然得到這個授權沒有確定錯誤

[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開啓成功。

回答

0

向typesToRead添加了HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!。我的帖子沒有顯示我使用了錯誤的類型:quantityType創建時distanceType

相關問題