Setting up HealthKit on independent Apple Watch app

I am creating an independent Apple Watch app that is not linked to an iPhone app. How can I request access to HealthKit data directly from the Apple Watch without requesting the HealthKit data via an iPhone app.


Apple recently announced that developers could now create independent Apple Watch apps in WWDC 2019, but I'm not finding documentation on how to use HealthKit on independent apps. I started following the instructions on this page here


https://developer.apple.com/documentation/healthkit/setting_up_healthkit


but the problem that I'm running into is that I can't figure out how to set the necessary custom messages for NSHealthShareUsageDescription and NSHealthUpdateUsageDescription. Apples documentation says to do this through the Info.plist, but I can't find these options anywhere for the just the Apple Watch.


Can anyone show how to use HealthKit for an independent Apple Watch app?

The keys you're looking for are NSHealthShareUsageDescription and NSHealthUpdateUsageDescription. Both are strings.


Add them to the Info.plist of your WatchKit extension and the watch will request the permissions.


Not that as of writing, when checking the permissions the watch will tell you they have been denied even though you allowed access. Improtatnly though, you still get access to the data.


-k.


You need another Info.plist file for the App Container. The important thing is not to include the new Info.plist as a target but rather in build settings for the App Container set the Info.plist file there. You can readmore in-depth details on setting up HealthKit privacy permissions in an Independent Watch App here.

I would hope this gets fixed some where in the pipeline between the Xcode template and App Store submission because this seems redundunt and a hack quite frankly.

In case of my standalone WatchOS app with access to Health Kit this helped (I learned it from the previous posts from fousa and Ryuuzaki in another thread):
  1. I added the keys "Privacy - Health Share Usage Description" and "Privacy - Health Update Usage Description" with some text as values in the file Info.plist in the folder [MyApp] WatchKit Extension.

  2. Then I created another folder [MyApp] on the same level as the folder [MyApp] WatchKit Extension.

  3. I copied the Info.plist file from the folder [MyApp] WatchKit Extension to the new folder [MyApp] and deleted all keys except the two mentioned above.

  4. Then under Targets (you get there when you click on your project name in the Project Navigator on the top of the left side in Xcode), I clicked on the first target (MyApp) and under Packaging for the key "Info.plist File" I added the path to the new Info.plist file - [Myapp]/Info.plist

I cleaned the build folder and got an error when I tried to build again (under top menu Product - Build) - some new error:
(error: Multiple commands produce '[...]/Info.plist': [...]

I restarted XCode, cleaned the build folder again and clicked on Build again. This time I was asked if it was ok if something was cleaned and I accepted.

Then it worked.

Note: In the past, I also had the keys mentioned above in the Info.plist file in [MyApp] WatchKit App and as I remember it caused problems. So in that file I do not have these two keys.

Setting up HealthKit on independent Apple Watch app
 
 
Q