2017-06-07 21 views
0

私は今のソリューションを把握しようと数日間、このエラーへの参照を使用してきた: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 DescriptionPrivacy - 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) 

答えて

0

HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceWalkingRunning)!をtypesToReadに追加しました。私の投稿は、distanceTypeを作成するときに間違ったタイプを使用したことを示していません:quantityType

関連する問題