Offline Support

Your Guide to Enabling and Utilizing Offline Support on iOS

Enabling Offline Support

Starting with version 3.1.x, the Brand Messenger Legacy's iOS SDK can utilize offline support to store messages that have failed while sending offline and then automatically resend them when network connectivity is restored.

🚧

v3.1.0 only provides support for text messages.

There are two levels of offline capabilities, one that requires no extra permissions or enabled modes but only works while the application is in the foreground, and the extra level that works while the app is in the background but requires the application to enable location updates while in background mode.

Offline Supported in...BenefitsRequirements
Foreground OnlyRequires no additional permissions.App must be in the foreground.
Foreground and BackgroundEnables offline capabilities whether the app is open in the foreground or background.Application needs permissions to perform regular location updates while it is in the background.

Foreground only mode

To enable offline capabilities while the app is in foreground mode, set the allowOfflineUsage flag in KBMSettings to true.

let settings = KBMSettings(integrationId: IOS_INTEGRATION_ID)
settings.allowOfflineUsage = true
BrandMessenger.initWith(settings) { (error: Error?, userInfo: [AnyHashable : Any]?) in }
KBMSettings *settings = [KBMSettings settingsWithIntegrationId:@"smoochIntegrationId"];
settings.allowOfflineUsage = true;
[BrandMessenger initWithSettings:settings completionHandler:^(NSError * _Nullable error, NSDictionary * _Nullable userInfo) {}];

Background mode

To enable offline capabilities while the app is in background mode, enable foreground and set allowOfflineUsageInBackground flag in KBMSettings to true.

let settings = KBMSettings(integrationId: IOS_INTEGRATION_ID)
settings.allowOfflineUsage = true
settings.allowOfflineUsageInBackground = true;
BrandMessenger.initWith(settings) { (error: Error?, userInfo: [AnyHashable : Any]?) in }
KBMSettings *settings = [KBMSettings settingsWithIntegrationId:@"smoochIntegrationId"];
settings.allowOfflineUsage = true;
settings.allowOfflineUsageInBackground = true;
[BrandMessenger initWithSettings:settings completionHandler:^(NSError * _Nullable error, NSDictionary * _Nullable userInfo) {}];

Also, enable Location Updates Background Mode in your application, and add the required strings to the application plist.

The SDK will request permission from the user to let the app use location data, using NSLocationAlwaysUsageDescription during init. See Apple's Developer Documentation for more information.

This will allow the app's code to continue running in the background to detect network connectivity changes. This will also increase battery consumption by the application.

Notes

If the application is closed completely (eg: force-closed or through device restart), the failed messages will only be reattempted when the app is reopened.