我尝试获取授权以保存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增加了功能但不是这个
答案 0 :(得分:2)
不允许应用使用HKCategoryTypeIdentifierAppleStandHour
类型保存样本。应用程序只能查询Apple Watch已存储在HealthKit中的现有工作时间。