Open HealthKit App from another app

依然范特西╮ 提交于 2020-01-10 18:22:10

问题


I want to build a fitness app that will upload the data to HealthKit. Is there any way to open/navigate to HealthKit from another app?


回答1:


On iOS 10, the Health app URL scheme is x-apple-health. You can open it from within your own app by calling:

Objective-C:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"x-apple-health://"]];

Swift:

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

See Open Health app using url scheme | Apple Developer Forums.




回答2:


iOS does not provide a general API for launching other applications and the Health app would need to have support for URL scheme in order for you to launch it from your own application. See Launch an app from within another (iPhone).




回答3:


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://")


来源:https://stackoverflow.com/questions/25259488/open-healthkit-app-from-another-app

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