ios - 允许访问 Health : how can I know in my app that the user enabled/disabled it later?

标签 ios swift notifications healthkit observers

当您调用 healthStore.requestAuthorization 方法并且用户在他第一次运行应用程序并显示对话框时不允许访问,如果他允许我如何在我的应用程序中观察稍后访问“健康”应用程序,以便再次尝试请求信息以显示在我的应用程序中?

我在 documentation 中找到的唯一订阅通知是 HKUserPreferencesDidChange 并且它不谈论授权状态,但是:

Notifies observers whenever the user changes his or her preferred units.

最佳答案

您不一定需要从 HealthKit 中实现任何东西来解决这个问题。您是否尝试过创建和检查 bool 值(即 isAuthorized)来处理状态?您可以在 View Controller 的 viewDidAppear(_:) 中进行检查,然后在 isAuthorized 为假时调用 healthStore.requestAuthorization。

此外,如果用户已经拒绝了最初的 HealthKit 请求,您可以转到一个新的 View Controller ,其中包含有关如何允许通过用户 iPhone 上的“设置”应用进行访问的说明。

关于ios - 允许访问 Health : how can I know in my app that the user enabled/disabled it later?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51233039/

相关文章:

objective-c - 在 Swift 2.1 中使用在 Objective C 中声明为 block 的闭包 Swift

python - Notify2 在 Python3 IDLE 中工作,但并不总是在终端中

google-chrome - 浏览器推送通知出现错误 "AbortError: Registration failed - push service not available"

iOS 人机界面指南 : Picker Control on iPad without Popover

ios - 在 iOS 中运行子进程?

ios - Swift:根据单元格数量动态更改单元格高度

firebase - Flutter - 在没有 firebase 身份验证的情况下将 firebase 通知推送给特定用户

iphone - 使用 Objective-C 类避免编译错误

iphone - EXC_BAD_ACCESS(Code=1…. 当使用 NSObject 作为委托(delegate)时

ios - 触摸文本框不起作用