2016-11-03 6 views
1

실제로 사용자의 dateofBirth 및 biologicalSex에 액세스하기 전에 권한이 결정되었습니다. 하지만 그것은 시뮬레이터에서 작동합니다.하지만 iphone과 쌍으로 연결된 시계에는 없습니다.Apple Health Kit 오류 도메인 = com.apple.healthkit Code = 5 "인증이 결정되지 않았습니다"

let birthdayType = HKQuantityType.characteristicType(forIdentifier: HKCharacteristicTypeIdentifier.dateOfBirth) 
    let biologicalSexType = HKQuantityType.characteristicType(forIdentifier: HKCharacteristicTypeIdentifier.biologicalSex) 
    let quantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate) 
    let readDataTypes: Set<HKObjectType> = [quantityType!, birthdayType!, biologicalSexType!] 
    guard HKHealthStore.isHealthDataAvailable() == true else { 
     label.setText("not available") 
     return 
    } 

    let readDataTypes: Set<HKObjectType> = self.dataTypesToRead() 

    healthStore.requestAuthorization(toShare: nil, read: readDataTypes) { (success, error) -> Void in 
     if success == false { 
      self.displayNotAllowed() 
     } 
    } 

    var birthDay: Date! = nil 
    do { 
     birthDay = try self.healthStore.dateOfBirth() 
    } catch let error as NSError{ 
     print("Either an error occured fetching the user's age information or none has been stored yet. \(error)") 
     return -1 
    } 
    var biologicalSex:HKBiologicalSexObject! = nil 
    do { 
     try biologicalSex = self.healthStore.biologicalSex() 
    }catch let error as NSError{ 
     print("Failed to read the biologicalSex! \(error)") 
    } 

답변

1

이것은 병행 문제이며 HealthKit 문제는 ​​아닙니다.

requestAuthorization이 대화 상자를 표시하고 결과를 백그라운드 프로세스에서 제공 할 수 있습니다.

생일 및 biologicalSex 읽기를 계속하기 전에 requestAuthorization의 답을 기다려야합니다.

+0

감사합니다. 문제를 해결했습니다. 내 watchOS의 버전은 2.2.1입니다. 시계와 IOS간에 healthstore의 데이터를 동기화 할 수 없습니다. 내 watchOS 버전을 업데이트합니다. 그것의 작품 :) – Maxwell