What is the purpose of HKHealthStore.isHealthDataAvailable? - ios

For setting up the HealthKit framework Apple recommends the following way:
Enable HealthKit capabilities in Xcode.
Check whether HealthKit is available on the device by calling the isHealthDataAvailable method.
If HealthKit is both enabled and available, instantiate a HKHealthStore object.
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 ?

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.

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.

Related

Keep rejecting my app because I don't clearly identify HealthKit functionality in my app's user interface

I've tried like 5 times with different combination of alert before the asking permission for writing on Health app (with the purpose: add workouts).
I also added an explicit phrase on app description and my info.plist has both NSHealthShareUsageDescription and NSHealthUpdateUsageDescription but they keep rejecting my app with this reason:
Guideline 2.5.1 - Performance - Software Requirements
Your app uses the HealthKit or CareKit APIs but does not indicate integration with the Health app in your app description and clearly identify the HealthKit and CareKit functionality in your app's user interface.
Next Steps
To resolve this issue, please clearly identify the HealthKit functionality in app's user interface to avoid confusion.
What can I do about it? In the last build I removed the HeathKit function so they maybe can approve with no other excuse but sooner or later I want to add this functionality...

Universal iOS app with HealthKit not showing up in iPad App Store

We have an iOS application that uses healthkit but we handle all cases of it gracefully for our iPad Application. After a successful submission we are not able to download it from the App Store directly on an iPad, but we can download it through iTunes. Is there something we need to do to make it appear on the iPad's App Store as well?
Does you plist contain healthkit under the required device capabilities? If it does, I'm guessing it won't show up on the iPad on the store, since the device doesn't fulfill the requirements. Downloading through iTunes won't filter out apps based on the requirements.
The fix would be to remove healthkit from the required capabilities and resubmit. The app should show up in the store for iPad then.
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW3
Found that we needed to weak link HeathKit in the Link Binary With Libraries section by making the Framework "Optional".

How to restrict my app to iphone 5s and above?

I am using healthkit in my application to read user's steps. But unfortunately iphone 5 and below does not have M7 sensor due to which my app can not perfome its full functionalities on those devices. So is there any possible way that user having iphone 5 or below could not install my app from app store ? Or any other possible workout/behaviour suggested ?
I think you want the HealthKit key of UIRequiredDeviceCapabilities in your .plist file.
Documentation on UIRequiredDeviceCapabilities is here
UIRequiredDeviceCapabilities (Array or Dictionary - iOS) lets iTunes and the App Store know which device-related features an app requires in order to run. iTunes and the mobile App Store use this list to prevent customers from installing apps on a device that does not support the listed capabilities.
The healthkit bit says:
healthkit Include this key if your app requires (or specifically prohibits) HealthKit.
I am afraid you can't restrict application to device specific.
All device requirement changes must be made when you submit an update
to your binary. You are permitted only to expand your device
requirements. Submitting an update to your binary to restrict your
device requirements is not permitted. You are unable to restrict
device requirements because this action will keep customers who have
previously downloaded your app from running new updates.
don't know any work around regarding Healthkit, still if any may result in app rejection.
The value of the UIRequiredDeviceCapabilities key is either an array
or a dictionary that contains additional keys identifying features
your app requires (or specifically prohibits).
Be sure to include keys only for the features that your app absolutely
requires. If your app can run without a specific feature, do not
include the corresponding key.
Can read more details in docs here:
https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/DeviceCompatibilityMatrix/DeviceCompatibilityMatrix.html

Binary Rejected for importing the Health kit but not implementing/using that

As I have submitted my first app on App Store but I got rejection with given reason-
27.6 Details
Your app also uses the HealthKit APIs but does not indicate integration with the Health app in your Application Description and clearly identify the HealthKit functionality in your app’s UI, as required by the App Store Review Guidelines.
I have implementing this feature for the next version so I am not using this framework anywhere in my project. Because of this I have also disable HealthKit capability Off from project setting like here Screenshot But they still rejecting the app. Do I have to submit again new binary or is there is way to continue with this?
disable the capability and don't link to the framework
a new binary is needed for sure to reflect both changes

Can I access healthkit data from iWatch extension?

I am making a iWatch app where I need to show data from healthkit. is it possible to access healthkit APIs from iWatch extension?
No. It's mentioned specifically in the HealthKit Framework Reference:
"You cannot access HealthKit from extensions (like the Today view) or from a WatchKit app."
What you can do is call openParentApplication:reply: to talk to the iPhone app itself and retrieve that data. Search around for that method name and you'll find some examples on how to call it and get data back to the Watch from it.
UPDATE: As others have mentioned below, this has changed for watchOS 2. The documentation has not been updated yet, but check out the WWDC 2015 videos for HealthKit and the Watch for some snippets of code you can use with the Xcode 7 beta.
Yes, in watchOS 2 you will be able to.
Yes, it's possible on watchOS 2.
However, it's a bit confusing, because it's still mentioned in the HealthKit Framework Reference for watchOS
You cannot access HealthKit from extensions (like the Today view) or from a WatchKit app.
Do not care about this.
Follow a few steps below.
Follow Setting Up HealthKit in the reference, you are now ready to access
Follow Accessing HealthKit Data, then you will be able to access
Make sure your application is running on watchOS 2.
Please see the reference for more detail.

Resources