gpt4 book ai didi

ios - Swift HealthKit 更新生日

转载 作者:行者123 更新时间:2023-11-28 11:22:45 26 4
gpt4 key购买 nike

我想更新 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)"
}

但是我如何以编程方式更改/更新生日?

感谢您的帮助!

最佳答案

您不能以编程方式更改这些特征。用户必须通过 Health App 输入此数据。

来自documentation

The HKCharacteristicType class is a concrete subclass of the HKObjectType class. HealthKit uses characteristic types to represent data that does not typically change over time. Unlike the other object types, characteristic types cannot be used to create new HealthKit objects. Instead, users must enter and edit their characteristic data using the Health app. Characteristic types are used only when asking for permission to read data from the HealthKit store.

关于ios - Swift HealthKit 更新生日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25965336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com