Does HealthKit sync data when the app is terminated?

I'm building an app with a leaderboard based on users' step counts, so I need the data to sync in real time at minimum.

The problem is that when the app is terminated, steps don't seem to be counted at all, so if a user hasn't opened the app in 5 days, the leaderboard ends up completely out of sync.

Is it even possible to retrieve this data when the app has been terminated and hasn't been opened?

I'm currently using Background Fetch, which works when the app is suspended, slowly, but it does work. However, it does not sync when the app is fully terminated.

Is your app an iOS app, watchOS app, or both? By “the data to sync in real time at minimum”, did you mean the Health store synchronization between your Apple Watch and it's paired iPhone, or the synchronization between your app and the Health store on the device?

The Health store synchronization between an Apple Watch and it's paired iPhone is never real-time, as discussed here.

To observe the change on the device's Health store when your app is suspended, consider using HKObserverQuery + enableBackgroundDelivery, as discussed here.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Does HealthKit sync data when the app is terminated?
 
 
Q