【问题标题】:Swift HealthKit update BirthdaySwift HealthKit 更新生日
【发布时间】:2014-09-22 00:46:03
【问题描述】:

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

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

感谢您的帮助!

【问题讨论】:

    标签: ios objective-c xcode swift healthkit


    【解决方案1】:

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

    来自documentation

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

    【讨论】:

      【解决方案2】:

      HealthKit 框架参考;

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-06
        相关资源
        最近更新 更多