HealthKit:保存HKCategoryTypeIdentifierAppleStandHour类型的样本

时间:2015-10-22 18:51:06

标签: ios swift health-kit

我尝试获取授权以保存HKCategoryTypeIdentifierAppleStandHour类型的样本:

var healthKitTypesToRead: Set<HKObjectType> = Set<HKObjectType>()
var healthKitTypesToWrite: Set<HKSampleType> = Set<HKSampleType>()
healthKitTypesToWrite.insert(HKSampleType.categoryTypeForIdentifier(HKCategoryTypeIdentifierAppleStandHour)!)
...
healthStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead) { 
    (success: Bool, error: NSError?) -> Void in

    if let error = error {
        dispatch_async(dispatch_get_main_queue(),{
            print ("success: \(success), error: \(error.localizedDescription)")
        })
    }
}

当我运行此代码时,我得到了异常

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'Authorization to share the following types is disallowed:
HKCategoryTypeIdentifierAppleStandHour'

我做错了还是Apple真的禁止写这种类型的样品?

使用(iOS 9.0和iOS 9.1)和XCode 7.1进行测试

修改 iOS 9.3 / watchOS 2.2增加了功能但不是这个

1 个答案:

答案 0 :(得分:2)

不允许应用使用HKCategoryTypeIdentifierAppleStandHour类型保存样本。应用程序只能查询Apple Watch已存储在HealthKit中的现有工作时间。