我似乎无法捕获和处理取消 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/