HealthKit error: Missing com.apple.developer.healthkit entitlement
Asked Answered
V

8

16

I'm adding code for HealthKit in my iOS Swift app, but I'm getting an error:

/* Ask for permission to access the health store */
override func viewDidAppear(animated: Bool) {
  super.viewDidAppear(animated)
  
  if HKHealthStore.isHealthDataAvailable(){
    
    healthStore.requestAuthorizationToShareTypes(typesToShare,
      readTypes: typesToRead,
      completion: {(succeeded: Bool, error: NSError!) in
        
        if succeeded && error == nil{
          println("Successfully received authorization")
        } else {
          if let theError = error{
            println("Error occurred = \(theError)")
          }
        }
      })

  } else {
    println("Health data is not available")
  }    
}

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

How can solve this?

Vitriform answered 23/9, 2014 at 10:56 Comment(1)
Given that the error is that you're missing the Health Kit entitlement, can we assume you've tried to fix it by adding the Health Kit entitlement?Overhead
H
49

I spent 3 days trying to figure out what was the problem. I found the solution with those steps:

enter image description here

  1. First go to the project (As I show in the image)
  2. Open projects and target lists
  3. Select nameApp WatchKit Extension
  4. Go to Capabilities tab, press on in Health Kit and voila... it is working for me.

I am using iOS 9.3.2 and Xcode 7.3.1

Halette answered 6/6, 2016 at 19:26 Comment(5)
bless you sir <3Allotrope
Thank you so much.Gain
This is the most up to date answer. Works with Xcode 9.2 and Swift 4Suricate
Xcode-12.0.1 iOS-14, watchOS-7: Everything is the same except the Capabilities tab is called Signing & Capabilities and you have to add Health Kit Capability by pressing the "+" button on the top rightPrepare
Doesn't work with Xcode 15.2Desiderative
P
16

That error is due to the fact that you have not added the HealthKit Entitlement to your target.

  1. Go to your project settings in Xcode.
  2. From there, navigate to the "Capabilities" Tab.
  3. Scroll down until you see "HealthKit" and flip the switch to on.
  4. Xcode will now add the HealthKit Entitlement to you Info.plist, your {ProjectName}.entitlements file, and your App ID on iTunes Connect

After following these steps, try to run your app again. This time around it should work.

Pumping answered 8/10, 2014 at 22:43 Comment(1)
Not necessarily: #33924041.Superlative
C
11

Both of the above answers should be tried first. If however

  1. You're sure the capability has been activated
  2. You're confident your app id associated with your provisioning profile has healthkit turned on and matches the app's bundle id

Then try and force the build to use that specific provisioning profile by selecting your target and going to

build settings -> code signing -> provisioning profile

and selecting it manually.

I've run into cases where get the above error in debug if 'automatic selection' is being used

Convector answered 21/2, 2015 at 4:2 Comment(2)
The weirdness with the provisioning profile can happen randomly even if everything was previously working - so this fixed it for meJudaize
Thanks. Despite adding the HealthKit capability to my watch extension, adding privacy descriptions to the watch extension's info.plist, I noticed that in (Xcode 11): Watch Extension -> Build Settings -> Signing -> Code Signing Entitlements, the entitlements file was only specified for 'Release' and not 'Debug'. Updating to use the entitlements file for both Release and Debug fixed the issue for me.Triacid
J
5

Activate Health kit in Capabilities

enter image description here

If still not worked

check:

  • Does your provisioning profile includes support for HealthKit?
  • Does your bundle identifier use the same ID referenced in the provisioning profile with support for HealthKit?
Just answered 16/10, 2014 at 13:52 Comment(0)
T
1

Some additional info that might help. If, under the HealthKit Capabilities the first step "add health kit entitlement to your app id" shows an error, and you have a "Fix This" button which does not do the job... read on...

Many times after working on multiple HealthKit test projects, you may find you have a Bundle ID that matches another Bundle ID used with another HealthKit project (say you duplicated the one project to spin off another test). This contention will show up as an error under the first checkmark in "iOS dev"s picture "add health kit entitlement to your app id". The error listed in the capabilities section unfortunately calls it an "app id" when you need to change the "Bundle ID". Add a number (or some character) in your bundle id string to make it unique. Then the "Fix" button in the HealthKit capabilities settings will work.

The Bundle ID (aka "App ID") is found under the "General" tab to the left of the "Capabilities" tab.

Torto answered 6/4, 2016 at 12:10 Comment(0)
A
0

This is bcz you have not Open the Capabilities tab in the target editor, and turn on the HealthKit switch.

and to resolve permission issues , add the following keys in info.plist and write causes.. according to your project requirements. 1.Health Update Usage Description 2.Health Records Usage Description 3.Health Share Usage Description

You can go ahead with free developer account also for authorisation purpose. good luck

Adagietto answered 30/1, 2019 at 6:44 Comment(0)
L
0

I did add both NSHealthShareUsageDescription and NSHealthUpdateUsageDescription (make sure the values to be greater than 12 characters - read it somewhere) in Info.plist

Next, similar to Jorge Luis Jiménez screenshot

  1. First go to the project (As I show in the image)
  2. Open projects and target lists
  3. Click on the Apps target (no need for watchkit extension)
  4. Now click on the + sign (Add Library) at the top right
  5. Add HealthKit.
Lumisterol answered 27/4, 2021 at 12:29 Comment(0)
L
0

I had a similar error when trying to start a workout on my AppleWatch from the iOS device, using this method: healthStore.startWatchApp(with: configuration, completion) { } method.

Interestingly enough, I had this error only in the Release mode when the HealthKit entitlement was added only to the WatchKit Extension target. Everything was working well in Debug.

Adding HealthKit entitlement also to the iOS target fixed the issue, but you won't be aware of this requirement until you run your app in Release or through the TestFlight.

Hope, this info will help someone

Lunisolar answered 11/6, 2022 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.