Configure Marketing Cloud Engagement
Runtime Toggles
Add Beacon Support
Enable Background Location Updates
Segment Location Messages
Event Tracking
Handle URLs
Data Protection and Privacy
Changelog
Normally, the app downloads new regions and messages as the device moves more than 5 kilometers from the last location and download of this data. However, if your app serves users who spend much time within a single 5-kilometer radius, consider adding the ability to do a background refresh of regions and messages. Apple controls when this background refresh takes place. However, Apple also allows the SDK to download new regions and messages for those times your user spends a considerable amount of time in a single 5-kilometer region.
In your Info.plist, implement this key to enable this function. To refresh geofences and beacons, the SDK requires the app to implement the App downloads content from the network mode. This mode gives the app permission to periodically download new regions and messages.
In your Info.plist, add keys under UIBackgroundModes:
1<array>
2 <!-- Perform periodic background app refreshes. -->
3 <!-- The **App downloads content from the network** mode is required. -->
4 <string>fetch</string>
5
6 <!-- Enable location in the SDK and allow ranging for beacons in the background. -->
7 <!-- The **App registers for location updates** mode is required. -->
8 <string>location</string>
9 <string>remote-notification</string>
10</array>In your application delegate method -application:didFinishLaunchingWithOptions:, implement this code:
1func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
2 ...
3 if UIApplication.shared.backgroundRefreshStatus == .available {
4 // setting this will enable iOS to call the app delegate method performFetchWithCompletionHandler periodically. The implementation of that method (see below)
5 // will call the MarketingCloudSDK at most once per day to update location and proximity messages in the background - if those services have been enabled.
6 // Only call this method if you have enabled location in your MarketingCloudConfiguration.json file
7 // Note that you will require "App downloads content from the network" in your plist for this background app refresh to work
8 UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
9 }
10}Finally, implement the handler for this functionality in your application delegate class.
For SDK v10 and later, use this code.
1MarketingCloudSdk.requestSdk { mc in
2 let location = mc?.lastKnownLocation()
3}For SDK v8, use this code.
1SFMCSdk.requestPushSdk { mp in
2 let location = mp.lastKnownLocation()
3}For SDK v7, use this code.
1// iOS calls this method to tell the MarketingCloudSDK to update location and
2// proximity messages. This method is only called if
3// [UIApplication sharedApplication] setMinimumBackgroundFetchInterval: is set
4// to a value other than UIApplicationBackgroundFetchIntervalNever and
5// Background App Refresh is enabled.
6func application(
7 _ application: UIApplication,
8 performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
9) {
10 MarketingCloudSDK.sharedInstance().sfmc_refresh(
11 fetchCompletionHandler: completionHandler
12 )
13}See MarketingCloudSDK+Base.h for more information about this method.