I can't get HealthKit to work. Missing Entitlement

混江龙づ霸主 提交于 2019-12-08 19:16:27

问题


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?


回答1:


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.




回答2:


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.

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.




回答3:


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).




回答4:


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.




回答5:


  1. Click on the Watch App Extension target.

  2. Tap on the Capabilities.

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




回答6:


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.




回答7:


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.



来源:https://stackoverflow.com/questions/27162123/i-cant-get-healthkit-to-work-missing-entitlement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!