0

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

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

感谢帮助!

4

2 回答 2

3

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

文档

HKCharacteristicType 类是 HKObjectType 类的具体子类。HealthKit 使用特征类型来表示通常不会随时间变化的数据。与其他对象类型不同,特征类型不能用于创建新的 HealthKit 对象。相反,用户必须使用 Health 应用程序输入和编辑他们的特征数据。仅在请求从 HealthKit 存储中读取数据的权限时才使用特征类型。

于 2014-09-22T04:25:48.043 回答
0

HealthKit 框架参考;

https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Framework/index.html#//apple_ref/doc/uid/TP40014707

HealthKit 对象可以分为两大类:特征和样本。特征对象表示通常不会改变的数据。这些数据包括用户的生日、血型和生理性别。您的应用程序无法保存特征数据。用户必须使用 Health 应用程序输入或修改此数据。

于 2014-10-08T09:47:49.760 回答