Plist values in Xcode Beta

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

Answered by SimplyKyra in 726908022

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

UPDATE: I figured out how to get past this error by going to App > Target > Info tab and added the three Privacy - Health... Usage Description Strings.

My issue now is I'm getting Code 1 Health data is unavailable when running on my non-beta Mac AND my beta iPad. I get error 4 when run on my simulator. Specifically Code=4 "Missing application-identifier entitlement. Is there anyway to debug/work with health data in a development setting? Or is there a way to get it working on the simulator?

After reading it seemed people got through this removing the app from the device. This is a newly created app. Removing from the simulator does not fix error. Another comment mentioned they got their error because of Apple account. I logged in with my Apple ID and I still got the same error.

Recap: Simulator iOS doesn't work as Code=4 "Missing application-identifier entitlement while my macOS Ventura 13.0 and non-beta iPad don't work as Code=1 "Health data is unavailable on this device".

Accepted Answer

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

Plist values in Xcode Beta
 
 
Q