Flush for Cocoa apps
Engagement stats (Events, Screens, Sessions, APIs) and Logs that are recorded by your app are batched together in a single session, i.e., foreground to background. The data is then uploaded in the Apptics server together on the next app launch. If the app is not launched to foreground again, it could take upto 1hour (approximately) for data to be uploaded based on your network connectivity and battery health.
You can use the flush method to try to instantly sync the recorded engagement data.
CopiedApptics.flush()
Flush method has rate limiting implemented to prevent throttling. Calling the flush method in short intervals will make it ineffective.
If your app supports BackgroundTask then you can enable BackgroundTask for Apptics by calling the following:
- Apptics.enableBackgroundTask(true)
- By setting AppticsConfig.default.enableBackgroundTask=true and add these lines to the completion handler of handleEventsForBackgroundURLSession in your AppDelegate.
Copied- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler{
if ([identifier hasPrefix:@"com.apptics.engagement.backgroundsession"]){
[[Analytics getInstance] setBgEngagementRequestSuccessBlock:completionHandler];
}
if ([identifier hasPrefix:@"com.apptics.nonfatal.backgroundsession"]){
[[Analytics getInstance] setBgNonFatalRequestSuccessBlock:completionHandler];
}
Copiedfunc application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
if (identifier.hasPrefix("com.apptics.engagement.backgroundsession")){
Analytics.getInstance().bgEngagementRequestSuccessBlock = completionHandler
}
if (identifier.hasPrefix("com.apptics.nonfatal.backgroundsession")){
Analytics.getInstance().bgNonFatalRequestSuccessBlock = completionHandler
}
}
Show full
Show less
- Add "com.apptics.engagement.bgtaskidentifier" and "com.apptics.nonfatal.bgtaskidentifier" to 'BGTaskSchedulerPermittedIdentifiers' in your main info.plist.
- The BGAppRefreshTaskRequest will be registered and scheduled just before the BackgroundTask expires and executed when the system launches your app in the background.
- Since we have used BGAppRefreshTaskRequest, make sure you have selected ”Background fetch“ in the background modes section of your project capabilities.
Note: Available only on iOS 13.0+, MAC Catalyst 13.0+, and tvOS 13.0+.