Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of HKHealthStore.isHealthDataAvailable?

For setting up the HealthKit framework Apple recommends the following way:

  1. Enable HealthKit capabilities in Xcode.
  2. Check whether HealthKit is available on the device by calling the isHealthDataAvailable method.
  3. If HealthKit is both enabled and available, instantiate a HKHealthStore object.
  4. Request authorization from the user to read and share HealthKit data.

My question is related with the number 2 step.

HealthKit is available as 8.0 and later and this method of course has the same availability. In iPad, in which HealthKit isn't available if you use the HealthKit entitlement, iOS doesn't let you even install the app at all.

What are the cases that this method can returns false ?

like image 625
Javier Cadiz Avatar asked Nov 22 '25 12:11

Javier Cadiz


2 Answers

As per the discussion in the documentation it is for iPad which as you mention does not have HealthKit. In the store HealthKit-Apps can still be available for iPad but will not work with that feature.

like image 188
Christian Avatar answered Nov 24 '25 03:11

Christian


Note that you can install an app that has the HealthKit framework on an iPad. What you can not do is install an app that has HealthKit as a requirement. By default, when you enable HealthKit in XCode, it adds both the entitlement, framework, and the requirement. But you can adjust the requirement in your app's .plist.

Now why would anyone want to include the HealthKit framework in an iPad app, especially if it doesn't have access to a HealthKit data store? The main reason I have found is then you can use all of the energy, distance, and weight unit formatting that is part of the HealthKit framework.

So, the isHealthDataAvailable is certainly desired for universal apps that use HealthKit but where the HealthKit store is not always available.

like image 22
lehn0058 Avatar answered Nov 24 '25 04:11

lehn0058



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!