1
我實際試圖訪問用戶的生物日期和bioSex之前確定授權。但它在模擬器上工作,但不是在iphone和配對手錶上。蘋果健康工具包錯誤域= com.apple.healthkit代碼= 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)")
}
謝謝。我已經解決了這個問題。我的watchOS版本是2.2.1。它無法在watch和IOS之間同步healthstore的數據。我更新了我的watchOS版本。是工作 : ) – Maxwell