Open Apple Health programmatically
Asked Answered
D

3

14

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?

Dido answered 29/7, 2016 at 15:32 Comment(2)
if u seaching for swift, have a look at this raywenderlich.com/86336/ios-8-healthkit-swift-getting-startedBacchanalia
Possible duplicate of Open HealthKit App from another appLenee
R
22

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

Robson answered 28/12, 2016 at 9:50 Comment(3)
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.Lenee
Is there any way to open the app for permission inside the health app?Mureil
@KrishnaKirana did you find an answer to this?Palatinate
F
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://")
Fulltime answered 21/11, 2019 at 7:29 Comment(1)
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.Chelseachelsey
L
-4

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

Lenee answered 2/8, 2016 at 1:14 Comment(1)
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 permissionsLump

© 2022 - 2024 — McMap. All rights reserved.