13

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?

SaltyNuts
  • 5,068
  • 8
  • 48
  • 80
  • if u seaching for swift, have a look at this https://www.raywenderlich.com/86336/ios-8-healthkit-swift-getting-started – Ulli H Jul 29 '16 at 15:40
  • 2
    Possible duplicate of [Open HealthKit App from another app](http://stackoverflow.com/questions/25259488/open-healthkit-app-from-another-app) – Allan Jul 30 '16 at 05:22

3 Answers3

20

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

Community
  • 1
  • 1
patrickS
  • 3,590
  • 4
  • 29
  • 40
  • 2
    This is not officially documented or supported, and could change at any time. It also doesn't address the request to open the app directly to the authorization control detail for your app. I don't recommend you use this. – Allan May 16 '17 at 16:15
  • 2
    Is there any way to open the app for permission inside the health app? – Krishna Kirana Sep 12 '19 at 14:17
  • @KrishnaKirana did you find an answer to this? – lukas Jul 14 '21 at 14:34
6

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: [:])
    }
}

Usage:

openUrl(urlString: "x-apple-health://")
José
  • 3,112
  • 1
  • 29
  • 42
Kevin Singh
  • 421
  • 8
  • 14
  • You might want to also do a check like: if (self.healthStore.authorizationStatus(for: HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bodyMass)!) == .sharingAuthorized) because for devices without Healthkit, they may be able to open the URL but not have healthkit. – Victor Engel Jul 23 '22 at 23:39
-4

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

Allan
  • 7,039
  • 1
  • 16
  • 26
  • This shouldn't be downvoted. There is no formal API to open Apple Health. There is the URL, but this isn't that helpful to help the user set their permissions – lewis Feb 28 '22 at 15:51