3.2.5. Setting up Background Tasks for Guaranteed Delivery
Custom Setup Guide
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
.
Mindbox records background tasks in AppDelegate. Read further for more information:
Registering background tasks
Register your background tasks in AppDelegate.swift to enable them.
import Mindbox
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
// To register background tasks for iOS v.13 and higher
if #available(iOS 13.0, *) {
Mindbox.shared.registerBGTasks()
} else {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
}
...
return true
}
// To register background tasks for iOS v. 12 and earlier
func application(
_ application: UIApplication,
performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Mindbox.shared.application(application, performFetchWithCompletionHandler: completionHandler)
}
}
Updated about 1 year ago