According to the Apple Developer Documentation, HealthKit should be available on macOS 13.0 and up, as seen in the following picture as well on Apple's documentation website.
The same can be said about HealthKit components, such as the HKHealthStore (see here for reference).
Before setting up HealthKit I check whether it is available using the following code:
if HKHealthStore.isHealthDataAvailable() {
print("is available")
} else {
print("is not available")
}
On iOS, this prints is available. From there I go on to set up HealthKit, ask for user permissions and so on. On macOS, however, .isHealthDataAvailable() is false.
Is there a way to get HealthKit running on macOS? Is there any additional setup necessary that is not necessary on other platforms?
what does it even mean for the framework to be available if there is no way to actually interact with it?
It means that the code will compile without having to add availability checks. Instead you use runtime checks and fall back to some default behavior when the data is not available. This has existed as long as HealthKit has been around because it's not available on iPad. Similarly, the data is not available on Mac, even though the framework exists.
Related
I'm working on an app that requires step counting.
There are several devices that don't support this feature (for example in my iPad mini 2, CMPedometer.isStepCountingAvailable() returns false).
Since the app heavily relies on the pedometer, I'd like to make it unavailable to download for unsupported devices.
I would expect to find a pedometer-related entry in the documentation of UIRequiredDeviceCapabilities, but there is none.
Is this possible in any way?
No, it is not possible to make an app unavailable for download on the basis of CMPedometer.isStepCountingAvailable(). The preferred method would be to display a notice to the user once downloaded, that their device does not support the required functionality.
I'm trying to implement an app that uses the BSSID of the network that the user is currently connected to on iOS 13.
However, Apple's documentation for CNCopyCurrentNetworkInfo on iOS 13 is not clear in its requirements for usage of their API.
It states the following in its description:
The requesting app must meet one of the following requirements:
The app uses Core Location, and has the user’s authorization to use location information.
The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.
The app has active VPN configurations installed.
This seems to suggest that only needs to meet one out of the 3 requirements listed above.
However, it subsequently states:
An app that fails to meet any of the above requirements receives the following return value:
An app linked against iOS 12 or earlier receives a dictionary with pseudo-values. In this case, the SSID is Wi-Fi (or WLAN in the China region), and the BSSID is 00:00:00:00:00:00.
An app linked against iOS 13 or later receives NULL.
This suggests that the app needs to meet all of the above requirements
This makes it extremely confusing as to what the requirements are, since the former part claims that you only need to implement one of the three in order to get the BSSID, whereas the latter part states that you won't get it if you miss out on any of the three requirements.
Any help on this would be much appreciated!
Your second quote does say ”any,” so not sure why you you think it suggests ”all.“
Have you tried it on 13.3 (17C54)?
I’ve had a few problems with a few apps. I started wondering if it was an “always enable location,” vs “only when using app.”
You do not appear to be alone in this problem.
According to the github thread below, SSID retrieval appears to be problematic even on the latest version of iOS (13.2.2).
In the link below, you will find that Apple has most likely fixed this issue on iOS 13.3, which is now in beta. I suggest we all test it and see what the results are.
https://github.com/HackingGate/iOS13-WiFi-Info/issues/7
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.
I am developing an iOS app that uses CloudKit. Apple's documentation says that I should use NSFileManager's ubiquityIdentityToken property to detect whether the service is available. But the property is always nil. How can I do to solve it? I am testing my app on an iPhone 5 simulator with iOS 8.2. And I have also logged into an iCloud account. I have also turned on iCloud Drive. (Someone says that turning on iCloud Drive may solve this problem, but this doesn't work for me.)
Do I need to call NSFileManager's method URLForUbiquityContainerIdentifier:? But Apple's documentation says that it is needed for document storage. It doesn't say that it is needed for CloudKit.
The CKContainer accountStatusWithCompletionHandler method is how you should check whether the user is logged into iCloud or not (supported since iOS 8.0). The CloudKit Quick Start shows an example of how to use it. fetchUserRecordIDWithCompletionHandler is another option that might make sense for your app.
In iOS 9.0, you'll also have CKAccountChangeNotification, which will notify your app when the iCloud status on the device changes.
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.