我尝试获取授权来保存 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'
我做错了什么或者苹果真的禁止编写这种类型的示例吗?
使用(iOS 9.0 和 iOS 9.1)和 XCode 7.1 进行测试
编辑 iOS 9.3/watchOS 2.2 添加了功能,但不是这个
最佳答案
应用程序不允许使用 HKCategoryTypeIdentifierAppleStandHour
类型保存示例。应用程序只能查询 Apple Watch 已存储在 HealthKit 中的现有站立时间。
关于ios - HealthKit:保存 HKCategoryTypeIdentifierAppleStandHour 类型的样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33288527/