Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSHealthShareUsageDescription must be set in the app's Info.plist in order to request read authorization

I have a framework that uses

_healthStore requestAuthorizationToShareTypes:writeTypes readTypes:readTypes completion:^(BOOL success, NSError *error) {

When I include the framework into my iOS app and put the following in my app info.plist file

<key>NSHealthShareUsageDescription</key>
<string>Read heart rate monitor data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>

everything works fine - not including those keys results in the following 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.'

My problem is that when running the unit tests for the framework it crashes with the above error. I've put the keys in all of the info.plist files for the framework and for the test target but still get the crash.

Which plist file should the keys go into in order to run the test target?

(should also mention that I'm in the process of switching over to Swift3 - this is part of the project that is in Objective-C - prior to iOS10 and XCode 8 this all worked fine).

I've created a framework with appropriate unit test to show the problem: https://github.com/asensei/HKHealthStoreFrameworkUnitTestBug

like image 975
BillBu Avatar asked Sep 20 '16 14:09

BillBu


2 Answers

You must add the NSHealthShareUsageDescription and NSHealthUpdateUsageDescription keys to the Info.plist file in your application. You do this by:

  1. Clicking on the "Info.plist" file

  2. Right clicking the screen and select add rows.

  3. scroll to "Privacy - Health Share.. " and "Privacy - Health Update.. "

  4. Select both of those and you should be good.
like image 151
Dre Avatar answered Oct 17 '22 23:10

Dre


You have to add two descriptions NSHealthUpdateUsageDescription and NSHealthShareUsageDescription, and then give each of them a description. See screenshot below.

enter image description here

like image 8
Johnny Avatar answered Oct 17 '22 23:10

Johnny