HealthKit Permission Sheet Not Appearing
Asked Answered
M

2

12

In my watch extension I call this function:

func requestAuthorization() {
        let healthStore = HKHealthStore()
        let workoutType = HKObjectType.workoutType()
        let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate)

        //reading
        let readingTypes = Set([heartRateType!, workoutType])

        //writing
        let writingTypes = Set([heartRateType!, workoutType])

        //auth request
        healthStore.requestAuthorization(toShare: writingTypes, read: readingTypes) { (success, error) -> Void in

            if error != nil {
                print("error \(error?.localizedDescription)")
            } else if success {
                self.startButton.setEnabled(true)
            } else if !success {
                self.startButton.setEnabled(false)
            }
        }
    }

And in AppDelegate.swift, I have:

func applicationShouldRequestHealthAuthorization(_ application: UIApplication) {
        let healthStore = HKHealthStore()
        healthStore.handleAuthorizationForExtension { (success, error) -> Void in
            //...
        }
    }

I get the dialog on my watch and phone and it opens the app on the phone when I tell it to from the dialog. The issue I'm having is that the phone app doesn't display the permission sheet that should show up in order to allow permissions. The permission sheet is mentioned here: https://developer.apple.com/reference/healthkit

What do I need to do to get it to appear so permissions can be granted? As it stand right now, I can grant permissions by going to the Health app then sources and select my app and grant the permissions that way.

The permission sheet I'm talking about is this. enter image description here

EDIT: I'm getting this error printed from the requestAuthorization() method call.

error Optional("Required usage description strings not present in app\'s Info.plist")
Mcdaniel answered 24/11, 2016 at 3:6 Comment(8)
Once you refused the authorization, you can only open this in settings. Or re-install the app.Intracranial
I never refused authorization. I tried re-installing the app and I still never get the permission sheet.Mcdaniel
Which iOS version are you using?Dryly
@Dryly iOS 10.1.1 and watchOS 3.1Mcdaniel
I am experiencing the same issue since I upgraded to 10.1.1Evelineevelinn
I fixed other permission issue by rebooting. Hope this will help!Intracranial
Did you manage to resolve this issue? I'm seeing the same in 10.3b6 / 3.1.3Extrauterine
Please post answer if you have found solutionDialysis
A
0

With this TestHealthKit, I was able to open the health-kit permission sheet.

        // 4.  Request HealthKit authorization
    (HealthStore as! HKHealthStore).requestAuthorizationToShareTypes(nil, readTypes: dataTypesToRead()) { (success, error) -> Void in

        //            self.CheckAuthorizationStatusFor(self.dataTypesToRead())
        if (success)
        {

            SuccessCompletion(success: success)
            return;
        }
        else
        {

            FailureCompletion(err: error)
            return;
        }

    }

Also, check have you enabled the entitlement as shown. entitlements .

Athiste answered 24/11, 2016 at 10:42 Comment(1)
That's exactly what I have and the entitlement is on. Everything in my app works if I go to the Apple Health app and grant permissions to my app from there. Literally the only issue I'm having is not seeing the permission sheet when the watch app requests permission from the phone and when I select to open the app from the alert on the phone, it opens my app but I don't see the permission sheet.Mcdaniel
T
-1

As stated in the documentation, you must add the necessary keys to .plist if your app uses APIs that read or update user health data.

NSHealthShareUsageDescription - A message to the user that explains why the app requested permission to read samples from the HealthKit store.

NSHealthUpdateUsageDescription - A message to the user that explains why the app requested permission to save samples to the HealthKit store.

Tyika answered 13/5, 2020 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.