7. iOS additional setup: Setting up Background Tasks for Guaranteed Delivery
Before you begin, make sure you’ve completed these steps:
Settings in xCode
Background tasks support the guaranteed delivery mechanism so that the SDK can pass events even if the app is in background mode.
To enable background tasks, add the following parameters into info.plist:
Required background modes:- App downloads content from the network;
- App processes data in the background;
- App downloads content in response to push notifications;
Permitted background task scheduler identifiers:cloud.Mindbox.$(PRODUCT_BUNDLE_IDENTIFIER).GDAppRefresh;cloud.Mindbox.$(PRODUCT_BUNDLE_IDENTIFIER).GDAppProcessing;cloud.Mindbox.$(PRODUCT_BUNDLE_IDENTIFIER).DBCleanAppProcessing.
Maestra records background tasks in AppDelegate. Read further for more information:
Registering background tasks
Register your background tasks in AppDelegate.m to enable them.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
// ...
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ...
if #available(iOS 13.0, *) {
Mindbox.shared.registerBGTasks()
}
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Mindbox.shared.application(application, performFetchWithCompletionHandler: completionHandler)
}
}// MINDBOX INTEGRATION
@import Mindbox;
@import MindboxSdk;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
// MINDBOX INTEGRATION
if (@available(iOS 13.0, *)) {
[[Mindbox shared] registerBGTasks];
}
else {
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
}
...
return true
}
// MINDBOX INTEGRATION
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[Mindbox shared] application:application performFetchWithCompletionHandler:completionHandler];
}
@endUpdated over 1 year ago

