Open Apple Health programmatically

我的未来我决定 提交于 2019-12-06 22:56:25

问题


Is it possible to open the Health app programmatically, like one can do with the Settings app?

If it's not possible to open the app's Apple Health permissions screen directly, can we at least open the main Apple Health screen?

Edit: I know that I cannot request permissions again - just like with other things like Camera access, etc. However, if the user refuses Camera permissions, I can direct them to the Settings page directly where they can change those permissions.

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];

Is there such a thing for Health App?


回答1:


It looks like since iOS 10+ it is possible to open the Health app.

UIApplication.shared.open(URL(string: "x-apple-health://")!)

For details take a look at this

Stackoverflow post




回答2:


Swift 5, safer way -

   func openUrl(urlString: String) {
    guard let url = URL(string: urlString) else {
        return
    }

    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    }
}

Usage:

openUrl(urlString: "x-apple-health://")



回答3:


The health permissions are opened only once automatically by the system at the time where you request the HealthKitStore for the right permissions. If the user refuses the permissions, you can not open them again. You could try to ask for an additional permission just to make the screen appear, but even if this might work I assume this is not what Apple intended with the default behaviour and might risk your app being refused.




回答4:


There is no API to send the user to the Health app.



来源:https://stackoverflow.com/questions/38662522/open-apple-health-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!