Home > Software engineering >  HealthKit availability on macOS
HealthKit availability on macOS

Time:01-28

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 Screenshot from Apple's documentation website showing platforms on which HealthKit is available, including macOS 13.0

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?

CodePudding user response:

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