Data Syncs when app is swiped closed
We sometimes get questions about expected behavior with our SDK and Apple Health when the application containing our SDK is swiped closed (force-quit) by the user.
Apple is pretty clear that they take swiping an app closed as clear user intent and have no documented way for an app to override the user’s choice. iOS purposely sets a flag that prevents the app from opening in the background when swiped closed. That flag is cleared when the user next launches the app manually.
What this means is there is no documented way for an application to sync data when an application is swiped closed. Therefore it is expected behavior that an application with our SDK enabled will not sync any data when the app is swiped closed. This would be true for any SDK framework running on iOS.
For HealthKit (Apple Health) specifically, the subscription observers need to be recreated immediately when the app is launched from a suspend or terminated state. To do this, you need to call [VLDHealthKitManager observeCurrentSubscriptions]
inside your application delegate’s application:didFinishLaunchingWithOptions:
function. Example:
func application(_ application: UIApplication didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
VLDHealthKitManager.sharedInstance().observeCurrentSubscriptions()
return true
}
Taking that action when the user launches the SDK enabled application after a forced quit state will ensure that you are syncing data continuously when the app is in the foreground or background.