HealthKit:保存 HKCategoryTypeIdentifierAppleStandHour 类型的样本
HealthKit: save samples of type HKCategoryTypeIdentifierAppleStandHour
我尝试获得授权以保存 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 增加了功能但不是这个
不允许应用程序保存 HKCategoryTypeIdentifierAppleStandHour
类型的示例。应用只能查询已由 Apple Watch 存储在 HealthKit 中的现有站立时间。
我尝试获得授权以保存 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 增加了功能但不是这个
不允许应用程序保存 HKCategoryTypeIdentifierAppleStandHour
类型的示例。应用只能查询已由 Apple Watch 存储在 HealthKit 中的现有站立时间。