iOS Advanced Configuration

Plist Configuration

OpenBack can be fully configured from your application Info.plist or from a separate file named OpenBack.plist. The plist configurations are optional and the default values will be used. The library will pick the settings from Info.plist first if the OpenBack dictionary key exists. It will fallback to using OpenBack.plist otherwise.

Available configuration keys:

KeyTypeDefaultDescription
AppCodestring-The OpenBack app code for your application
AppGroupstring-The app group used for OpenBack and notification app extenstions
DebugLevel1integer0The debug log level - see debug levels
EnableAutoStart2booleantrueControls if OpenBack starts automatically
ClearBadgeCount5booleanfalseControls if OpenBack clears the badge number when app is opened (only if badge is enabled)
EnableCoreMotionActivitybooleanfalseControls if library can use Core Motion Activity manager.
EnableMicrophonebooleanfalseControls if OpenBack can use the microphone (noise trigger)
EnableProximity3booleanfalseControls if OpenBack can use the proximity sensor (proximity trigger)
EnableSwizzle4booleantrueControls if swizzle is enabled
LargeIconstring-Default large icon for notification (filename in main bundle or image asset name)
NotificationSoundstring-Set the default notification sound (filename in main bundle)
  • [1]: Using the debug level in the plist during development can be useful to get startup logs that might occur before you have a chance to call the API.
  • [2]: If you disable auto-start, you will need to manually call `+ start:` in your application.
  • [3]: Enabling proximity on iOS has the side effect of turning the screen off when the device is close to the face.
  • [4]: If you disable delegate swizzling, you will need to manually call OpenBack functions. See below for more details.
  • [5]: If you enable clearing the badge count on app launch, the SDK will set the badge count to 0 but keep the notifications in the notification center. This is done by setting the `applicationIconBadgeNumber` to -1. Setting a value of 0 would have the side effect of removing all the delivered notifications.

You can override some settings (AppCode, DebugLevel, EnableAutoStart) using the API. The API settings will take precedence.

Example:

<plist version="1.0">
<dict>
...
<key>OpenBack</key>
<dict>
<key>AppCode</key>
<string>YOUR_APP_CODE</string>
<key>AppGroup</key>
<string>group.YOUR_APP_GROUP</string>
<key>DebugLogLevel</key>
<integer>5</integer>
<key>EnableAutoStart</key>
<true/>
<key>EnableProximity</key>
<false/>
<key>EnableSwizzle</key>
<true/>
<key>NotificationSound</key>
<string>ding.m4r</string>
</dict>
...
</dict>
</plist>

Swizzle

Be default, OpenBack swizzles some methods in order to intercept system calls related to notifications. The goal is to simplify integration so you do not need to add more code to your application.

There are no side effects to your project but if you are using other 3rd party library that also swizzle classes, you might see some issues. We test our SDK with the most common SDKs like Firebase, Facebook, etc... to make ensure everything works as expected.

If you prefer to avoid OpenBack using swizzle, set the EnableSwizzle key in the plist to false. You must then call a few OpenBack functions so it can run properly.

These functions are listed in the public headers:

  • OpenBackAppDelegate.h
  • OpenBackUserNotificationDelegate.h

App Delegate

Check the OpenBackAppDelegate.h header for the functions

Here is an example of an application delegate with all the required calls:

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set Notification Categories
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center setNotificationCategories:[OpenBack notificationCategories]];
// Here we're using OpenBack categories only, but you can merge them with your set
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[OpenBack handleAppDidRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
...
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[OpenBack handleAppDidFailToRegisterForRemoteNotificationsWithError:error];
...
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if ([OpenBack handleAppDidReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]) {
// OpenBack handled the remote notification - will call the completion handler
return;
}
// Your code
}
// If targeting iOS < 13
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Your code
UIBackgroundFetchResult result = ...;
// Call OpenBack
[OpenBack handleAppPerformFetch:result completionHandler:completionHandler];
}
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
if ([OpenBack handleEventsForBackgroundURLSession:identifier completionHandler:completionHandler]) {
// Handled by OpenBack - completion handler will be called
return;
}
// Your code
}
@end

Notification Delegate

@implementation MyNotificationDelegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
if ([OpenBack handleUserNotificationCenter:center willPresentNotification:notification completionHandler:completionHandler]) {
// Handled by OpenBack - completion handler will be called
return;
}
// Your code
completionHandler(UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
if ([OpenBack handleUserNotificationCenter:center didReceiveNotificationResponse:response completionHandler:completionHandler]) {
// Handled by OpenBack - completion handler will be called
return;
}
completionHandler();
}
@end