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];
}
	

@end