Hey,
I'm coding my app in the Xcode Beta 2 and am attempting to access the HKHealthStore()
to add a HKCategorySample
. When I run the app and attempt to add the sample I get the following error:
Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}
When I make sure to requestAuthorization
before running the code I get a different error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSHealthShareUsageDescription must be set in the app's Info.plist in order to request read authorization for the following types: HKCategoryTypeIdentifierMindfulSession'
I'm assuming I need to add to my Info.plist but am unable to figure out how. If I go to my project or project's target and access Build Settings
I see the following image:
But am unable to edit it. I assuming I want to add NSHealthShareUsageDescription
with a String explanation for why I want access but anything I find online is for an older Xcode so I don't know how to do it.
Any help to get this working would be really appreciated. Thank you
In case anyone has the same issue I wanted to share how I fixed it.
The original question complained about the following error:
Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}
I ultimately fixed it by going to App > Target > Info tab and added the three Privacy - Health... Usage Description
Strings. Later I realized I only needed one for my purposes. Also, before or during this process, I went to App > Target > Signing & Capabilities tab and pressed the plus in the top left corner to add HealthKit iOS. Here are the photos showing this:
The signing and capabilities needed HealthKit added (not sure if this is REQUIRED but figured I'd share.
This fixed the above error but brought me to the next one.
Error Domain=com.apple.healthkit Code=4 "Missing application-identifier entitlement" UserInfo={NSLocalizedDescription=Missing application-identifier entitlement}
I couldn't figure it out and then finally asked on StackOverflow and got the answer..
The main portion was adding the Privacy - Health Update Usage Description
string to the Info tab. Originally I added all three Privacy - Health --- Usage Description
but after it worked I went back and removed the ones that weren't needed.
. To fix it you need to go to your entitlements file (icon has a yellow checkmark with a squiggly circle around it) and manually add application-identifier
, change the type to a String, and set the value to your Bundle Identifier (found under App > Target > Signing and Capabilities > Signing). Later I noticed the Bundle Display Name
under the info tab so not sure if those two are connected.
Good luck :)