我想在 Apple Health 中更新生日。但我不知道怎么做。
这是我的授权功能:
private func requestAuthorisationForHealthStore() {
let dataTypesToWrite = [
HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth),
HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass),
HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight)
]
let dataTypesToRead = [
HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth),
HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass),
HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight)
]
self.healthStore?.requestAuthorizationToShareTypes(NSSet(array: dataTypesToWrite),
readTypes: NSSet(array: dataTypesToRead), completion: {
(success, error) in
if success { println("User completed authorisation request.") }
else { println("The user cancelled the authorisation request. \(error)") }
})
}
为了请求生日,我调用我的函数:
func requestAgeAndUpdate() {
var error: NSError?
let dob = self.healthStore?.dateOfBirthWithError(&error)
if error != nil {
println("There was an error requesting the date of birth: \(error)")
return
}
self.ageLabel.text = "\(dob)"
}
但是我如何以编程方式更改/更新生日?
感谢帮助!