Health data on iPad via iCloud

What’s the recommended way to determine whether HealthKit data is being accessed on an iPad versus an iPhone?

My goal isn’t really to identify the device type itself, but to know whether the HealthKit data is likely being viewed on the device where it was originally recorded, or on a device that receives the data via HealthKit/iCloud syncing. This matters because synced HealthKit data can appear with a delay, and I’d like to set appropriate expectations for users.

I previously used UITraitCollection.current.userInterfaceIdiom == .pad as a proxy for this, but that API is being deprecated. Is there a better way to distinguish between locally recorded HealthKit data and data that has arrived via sync, or otherwise identify when the app is running on an iPad?

Answered by Engineer in 892570022

Thanks for additional clarification. At the moment, all the information about the source device is going stored via the HKSource for the object. If you'd like to continue checking for the app running on iPad, the system APIs will be your best source of information: https://developer.apple.com/documentation/uikit/uidevice/model?language=objc

That being said, if you'd like to see this sort of information being provided on the sample, we'd encourage filing a Feedback Request to build something to fit your needs.

Samples have HKDevice associated with them and you can determine what the local device is. More information available here: https://developer.apple.com/documentation/healthkit/hkdevice/local()

You can also utilize this in predicates for queries.

Hi simonfromhelix, to clarify, it sounds like you're trying to determine whether a sample came from the current device rather than a specific device idiom, is that right?

You may find what you're looking for in HKSourceRevision, which provides information about the device the sample came from.

Is the work you're doing dependent on the device idiom at all (e.g. iPhone vs iPad)? Or are you trying to use the current device as a proxy for understanding which data is live data?

Sorry, I‘ve not been clear enough with the question, I’m trying to determine if the device is viewing the Health data via synchronised iCloud or directly on device. The reason being the data via iCloud is often is delayed and so I’m trying to ensure I can provide the right experience to the user and set expectations.

My app displays Apple Watch Health data and generally the paired iPhone‘s Health data stays right up to date with Apple Watch, but this isn’t the case for the iPad that also accesses the same data via iCloud.

It’s not explicitly clear, but this delay issue might be something that is improved with the new 27 releases?

Thanks for additional clarification. At the moment, all the information about the source device is going stored via the HKSource for the object. If you'd like to continue checking for the app running on iPad, the system APIs will be your best source of information: https://developer.apple.com/documentation/uikit/uidevice/model?language=objc

That being said, if you'd like to see this sort of information being provided on the sample, we'd encourage filing a Feedback Request to build something to fit your needs.

Health data on iPad via iCloud
 
 
Q