16

我想构建一个将数据上传到 HealthKit 的健身应用程序。有没有办法从另一个应用程序打开/导航到 HealthKit?

4

3 回答 3

20

在 iOS 10 上,健康应用 URL 方案是x-apple-health. 您可以通过调用从您自己的应用程序中打开它:

目标-C:

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

迅速:

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

请参阅使用 url 方案的 Open Health 应用程序 | 苹果开发者论坛

于 2016-11-08T11:37:15.993 回答
4

iOS 不提供用于启动其他应用程序的通用 API,并且 Health 应用程序需要支持 URL 方案,以便您从自己的应用程序启动它。请参阅从另一个 (iPhone) 中启动应用程序

于 2014-08-30T21:03:48.340 回答
3

Swift 5“更安全的方式”

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

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

用法:

openUrl(urlString: "x-apple-health://")
于 2019-11-20T15:23:30.053 回答