ios - HKHealthStore 请求AuthorizationToShareTypes :readTypes:completion always returns success?

标签 ios ios8 healthkit

我似乎无法捕获和处理取消 HealthKit 权限的用户。完成 block 总是返回成功和 nil 错误。

[[DataManager healthStore] requestAuthorizationToShareTypes:dataTypesToWrite
                                                  readTypes:dataTypesToRead
                                                 completion:^(BOOL success, NSError *error)
 {
     if (!success)
     {
         NSLog(@"You didn't allow HealthKit to access these read/write data types. In your app, try to handle this error gracefully when a user decides not to provide access. The error was: %@. If you're using a simulator, try it on a device.", error);
     }

     if (completion)
     {
         completion(success,error);
     }
 }];

最佳答案

成功参数并不指示您的应用是否获得了所请求的授权。它仅指示用户是否成功提示授权(如果需要提示)。如果用户取消提示或由于某种原因无法显示提示,则 success 参数将为 NO,并且错误将为非 nil。

另请注意,根据设计,无法查询应用程序是否具有某种类型的读取访问权限。您只能使用 -[HKHealthStoreauthorizationStatusForType:] API 查询应用程序是否有权保存某种类型的对象。

关于ios - HKHealthStore 请求AuthorizationToShareTypes :readTypes:completion always returns success?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25400102/

相关文章:

swift - 在 UIButton 上设置图像和标题

ios - 如何在 iOS 应用程序中从 Health 应用程序获取事件的唯一标识符?

ios - 我的 native 应用程序在Swift中编译器生成的崩溃

ios - 设置是否没有观察模型属性的变化 - Swift

ios - 显示 YouTube 注释 - iOS 应用程序

ios - 在 ARSCNView 中禁用实时摄像头馈送?

ios - AppleLanguages 不再返回所有语言

ios - 从 UICollectionView 中删除所有单元格空间

ios - UITables 节标题中的多行文本

ios - 在 HealthKit HKStatisticsQuery 中收到 "Type of expression is ambiguous without more context"作为错误