I can't get HealthKit to work. Missing Entitlement
Asked Answered
T

7

7

I am having a hard time to get HealthKit working for my iOS App. I have done all the steps I have found so far and none seem to solve my problem I keep getting this error when trying to authorize Healthkit:

Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo=0x78fa24e0 {NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}

Here is my code asking for authorization:

    if([HKHealthStore isHealthDataAvailable]) {

        self.healthStore = [[HKHealthStore alloc] init];

        [self.healthStore requestAuthorizationToShareTypes:nil readTypes:[self dataTypesToRead] completion:^(BOOL success, NSError *error) {

            if (!success) {
                NSLog(@"HK Error: %@", error);
                [self presentHealthAlert:@"You didn't allow APP to access HealthKit Data. Please go to Settings and set up APP permissions." withTitle:@"Error"];
            } else {
                [self presentHealthAlert:@"Thank You For Access" withTitle:@"Success"];
            }
        }];

    } else {
        [self presentHealthAlert:@"Health Data Not Available" withTitle:@"Success"];
    }

And Yes, I have enabled it on my project Capabilites, and yes I have enabled it in my Dev Center App ID. Is there anything else I might be missing?

Tussah answered 27/11, 2014 at 2:24 Comment(1)
Did you try downloading the provisioning profile and trying again?Afore
M
6

I had this problem with a watchOS 2 app. The resolution was to ensure I had enabled the HealthKit entitlement for both the iOS app and the watch extension.

I had wrongly assumed the switch for the iOS app would be inherited by the watch extension.

Mott answered 30/9, 2015 at 7:19 Comment(1)
Thank you for this! Not one thing I saw anywhere mentioned this so I never thought of looking for another set of entitlements to enable!Spat
D
2

I ended up here after reaching my wit's end. Nothing worked and I clearly had the HealthKit entitlement enabled so finally I just restarted the phone. Voilà. Restarting cleared the missing entitlement errors.

Doggy answered 18/5, 2015 at 0:13 Comment(0)
L
1

You have to make sure that you click on your program on the left side of Xcode (the top of your file hierarchy). You'll come to a general settings screen in the main window (to the right) where you will see your bundle identifier, deployment target, and additional settings. Click on the tab at the top that says Capabilities. Now you will see a toggleable list which includes HealthKit. You have to activate it here before you can use it in the app.

Edit: Here is an image from Xcode that might help you find this if you're not familiar with setting dependencies or other program specific settings.

Screenshot showing where the list with HealthKit is

It is in this list on the right, towards the bottom you'll see HealthKit. It will check several things once you toggle it on and verify that you can use it.

Lazor answered 27/11, 2014 at 13:19 Comment(0)
L
1

A bit old, but for anyone else who has issues, I had to manually refresh my provisioning profiles as well in XCode 6.2 (Preferences -> Accounts).

Lanneret answered 17/3, 2015 at 8:1 Comment(0)
A
1
  1. Click on the Watch App Extension target.

  2. Tap on the Capabilities.

  3. Scroll down to the bottom and turn on the HealthKit.

enter image description here

Arceliaarceneaux answered 27/10, 2017 at 21:3 Comment(0)
S
0

I managed to get my entitlement working by ensuring that I had a device registered. Once I got my iPhone showing under the simulator and I didnt have any unresolved issues under the identity section of the app it all loaded ok.

Spermicide answered 28/2, 2016 at 15:16 Comment(0)
T
0

You may find that although you have turned on the HealthKit entitlement on in xcode that there is a second entitlements file that does not contain the healthkit boolean. I found that while the obvious entitlements file (at the top level) had the correct information, a different entitlements file had been created under Resources that did not contain the healthkit entitlement. fixing that file fixed my problem.

Taconite answered 7/6, 2017 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.