Open Health Kit Permission Settings for the app that uses Health Kit
Asked Answered
V

0

7

I am using Health Kit to display steps information for the user.

let healthKitTypes: Set = [ HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!]

self.healthStore.requestAuthorization(toShare: healthKitTypes, read: healthKitTypes) { (bool, error) in
    
    if (bool) {
        // Auth granted
    } else {
        // Navigate user to HealthKit app permissions
    }
}

This code shows a popup to the user with the asked permissions. What I want to do in the // Navigate user to HealthKit app permissions is to open the Health Kit app permission settings directly for my app if the user did not approve the permissions on the popup.

I know that settings of the app can be opened by using something like this:

let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in

    guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
        return
    }

    if UIApplication.shared.canOpenURL(settingsUrl) {
        UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
            print("Settings opened: \(success)") // Prints true
        })
    }
}

... I want to do similar, just in this case open the Health Kit Setting permission screen so that users can enable the requested permissions directly in settings - if they decline them in the app popup.

Thanks

Valoniah answered 15/9, 2020 at 8:37 Comment(6)
This was a commented post with similar question. The main problem is that health permissions are opened only once automatically by the system at the time where you request the HealthKitStore permissions. So if user refuses the permissions once, you can not open them again. Once user refuses permissions, you have to point the use to follow some steps to activate them (Go to settings -> Privacy -> Health -> etc) I have worked with Health kit and I only see that auto pop up one time per clean installation. Hope it helps.Harriette
I agree with the fact about auto popup, but I've seen various applications opening health settings screen directly for that specific app where you can re-enable them again. That is what I really want.Valoniah
@Valoniah did you figure this out?Beane
@Beane nah not yetValoniah
@Valoniah did you figure it out now?Vanny
if someone still looking this is the url - URL(string: "App-prefs:HEALTH&path=SOURCES")Voguish

© 2022 - 2024 — McMap. All rights reserved.