ios - HealthKit:保存 HKCategoryTypeIdentifierAppleStandHour 类型的样本

标签 ios swift 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'

我做错了什么或者苹果真的禁止编写这种类型的示例吗?

使用(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/

相关文章:

ios - 释放后访问实例变量

ios - 确定 NSUInteger 是否有值或为 nil

ios - UICollectionView 如何找到单元格结束的行

ios - HealthKit:收到由 body 事件,背景和终止状态触发的通知(Obj-C,iOS 10.3)

ios - 应用程序本地化方法的优缺点?

ios - 如何删除显示中的网址 :standalone IOS PWA?

UIPageViewController 的 Ios 下拉刷新策略

arrays - Swift3 iOS -Firebase 如何将节点数据分离到不同的数组和字典中

ios - 如何修复此错误 : 'Foundation._GenericObjCError error 0. '

ios - HealthKit 错误 : Error Domain=com. apple.healthkit Code=100 "Failed to open database"UserInfo= {NSLocalizedDescription=无法打开数据库}