Advanced push configuration

Customize the SDK default launching configuration

The library provides a number of advanced configuration features that can be controlled with the ACCConfiguration object.

The configurations can be set simply by using the AccengageConfig.plist you've added to your project, or at runtime using the exposed properties of the ACCConfiguration object. See the ACCConfiguration documentation for the full list of configuration options.

IDFA collection

The IDFA (Identifier for Advertisers), is automatically collected by the library. Note that you can disable the IDFA collection by setting the property to NO.

Automatic integration

It's not required to implement the notification-related delegate methods. The library can intercept the UIApplicationDelegate and UNUserNotificationCenterDelegate and forward them to your original delegate.

This should be compatible with the majority of application use cases, but if you prefer, you can disable this behaviour.

By default, automatic integration is enabled. To disable it, change the automaticPushDelegateEnabled property of your ACCConfiguration object to NO.

If you choose to disable the automatic integration, you will need to implement all notification-related UIApplicationDelegate and UNUserNotificationCenterDelegate methods. See Handling push delegate callbacks manually for more details.

Tracking mode

Depending on your privacy rules, you can decide to choose the restricted tracking mode which disables the collection of certain device data such as connection type, carrier name, local date and jailbreak state.

Note that if you use the restricted mode, some advanced targeting features may not be available. This restriction is not recommended for most integrations.

Session timeout

The library provides automated session management. This value indicates how long (in seconds) the app may be in the background before starting a new session upon resume. A default implementation has a session timeout period of 5 minutes. If the app remains in the background for longer than the session timeout period, the next time it's opened a new session will be started.

Delay SDK Launch

If you prefer to start the SDK with a delay (e.g. as a result of a user action), you'll need to pass the launch options information to the SDK. This information is provided by the system in the didFinishLaunchingWithOptions: callback and should be set using the launchOptions property of the ACCConfiguration object.

Custom notification sounds

You can specify a custom sound, that iOS will play when it receives a local or remote notification for your app. For more details, you can consult Apple's documentation.

Remember that the default sound is played when:

  • The sound file is not found.
  • The sound is longer than 30 seconds.
  • The data format is invalid. Accepted data formats are: aiff, wav, or caf.

To add the sound file to your project, you can simply drag and drop it to your resource folder. Make sure you check the box Copy items if needed.

In the Accengage dashboard, you can easily specify this sound when composing a push message by selecting "custom" in the sound section, and enter the file name with its extension (customsound.wav for instance).

Configure interactive notifications

Interactive notifications give the user a quick and easy way to perform relevant tasks in response to a notification. Instead of the user being forced to launch your app, the interface for an actionable notification displays custom action buttons that the user can tap. When tapped, each button dismisses the notification interface and forwards the selected action to your app for immediate handling. Forwarding the action to your app avoids the need for the user to navigate further in your app to perform the action, thereby saving time.

A set of default notifications categories is provided by Accengage. If you want to add more categories for interactive notifications, you should call the setCustomCategories: before registering for Push Notifications:

Objective-C:

// The app custom categories set
NSMutableSet *customCategories = [NSMutableSet set];

UNNotificationAction *acceptAction = [UNNotificationAction actionWithIdentifier: @"ACCEPT_ACTION" title: @"Accept" options: UNNotificationActionOptionNone];

UNNotificationAction *declineAction = [UNNotificationAction actionWithIdentifier: @"DECLINE_ACTION" title: @"Decline" options: UNNotificationActionOptionNone];

UNNotificationCategory *meetingInviteCategory = [UNNotificationCategory categoryWithIdentifier:@"MEETING_INVITATION" actions:@[acceptAction, declineAction] intentIdentifiers: @[] options:UNNotificationCategoryOptionCustomDismissAction];

[customCategories addObject:meetingInviteCategory];

[[Accengage push] setCustomCategories:customCategories];

// Register for notification
ACCNotificationOptions options = (ACCNotificationOptionSound|ACCNotificationOptionBadge|ACCNotificationOptionAlert|ACCNotificationOptionCarPlay);

[[Accengage push] registerForUserNotificationsWithOptions:options];

Swift:

// The app custom categories set
var customCategories: Set<UNNotificationCategory> = []

let acceptAction = UNNotificationAction(identifier: "ACCEPT_ACTION", title: "Accept", options: UNNotificationActionOptions(rawValue: 0))

let declineAction = UNNotificationAction(identifier: "DECLINE_ACTION", title: "Decline", options: UNNotificationActionOptions(rawValue: 0))

let meetingInviteCategory = UNNotificationCategory(identifier: "MEETING_INVITATION", actions: [acceptAction, declineAction], intentIdentifiers: [], options: .customDismissAction)

customCategories.insert(meetingInviteCategory)

Accengage.push()?.customCategories = customCategories

// Register for notification
Accengage.push()?.registerForUserNotifications(options: [.notificationOptionSound, .notificationOptionAlert, .notificationOptionBadge, .notificationOptionCarPlay])

Handling push delegate callbacks manually

If you choose to disable the automatic integration, by changing the automaticPushDelegateEnabled property of your ACCConfiguration object to NO, you will need to add the following code:

  1. Set UNUserNotificationCenter delegate

Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Set up the UNUserNotificationCenter delegate
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
}

Swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    // Set up the UNUserNotificationCenter delegate
    UNUserNotificationCenter.current().delegate = self
}
  1. Implement the delegates methods:

Objective-C:

// UIApplicationDelegate methods

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken {
    [[Accengage push] didRegisterForUserNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
    [[Accengage push] didReceiveRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNoData);
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(nonnull NSDictionary *)userInfo completionHandler:(nonnull void (^)())completionHandler {
    [[Accengage push] handleActionWithIdentifier:identifier forRemoteNotification:userInfo];
    completionHandler();
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(nonnull NSDictionary *)userInfo withResponseInfo:(nonnull NSDictionary *)responseInfo completionHandler:(nonnull void (^)())completionHandler {
    [[Accengage push] handleActionWithIdentifier:identifier forRemoteNotification:userInfo withResponseInfo:responseInfo];
    completionHandler();
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(nonnull UILocalNotification *)notification {
    [[Accengage push] didReceiveLocalNotification:notification];
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(nonnull UILocalNotification *)notification completionHandler:(nonnull void (^)())completionHandler {
    [[Accengage push] handleActionWithIdentifier:identifier forLocalNotification:notification];
    completionHandler();
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(nonnull UILocalNotification *)notification withResponseInfo:(nonnull NSDictionary *)responseInfo completionHandler:(nonnull void (^)())completionHandler {
    [[Accengage push] handleActionWithIdentifier:identifier forLocalNotification:notification withResponseInfo:responseInfo];
    completionHandler();
}

// UNUserNotificationCenterDelegate methods

- (void) userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    completionHandler([[Accengage push] willPresentNotification:notification]);
}

- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    [[Accengage push] didReceiveNotificationResponse:response];
    completionHandler();
}

Swift:

// UIApplicationDelegate methods

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Accengage.push()?.didRegisterForUserNotifications(withDeviceToken: deviceToken)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    Accengage.push()?.didReceiveRemoteNotification(userInfo)
    completionHandler(.noData)
}

func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
    Accengage.push()?.handleAction(withIdentifier: identifier!, forRemoteNotification: userInfo)
    completionHandler()
}

func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable : Any], withResponseInfo responseInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
    Accengage.push()?.handleAction(withIdentifier: identifier!, forRemoteNotification: userInfo)
    completionHandler()
}

func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
    Accengage.push()?.didReceive(notification)
}

func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, completionHandler: @escaping () -> Void) {
    Accengage.push()?.handleAction(withIdentifier: identifier, for: notification)
    completionHandler()
}

func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, withResponseInfo responseInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
    Accengage.push()?.handleAction(withIdentifier: identifier, for: notification)
    completionHandler()
}

// UNUserNotificationCenterDelegate methods

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (_ options: UNNotificationPresentationOptions) -> Void) {
    completionHandler((Accengage.push()?.willPresent(notification))!)
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    Accengage.push()?.didReceive(response)
    completionHandler()
}

To enable the Carousel template in your project, you will need to create a Notification Content Extension.

Img

  1. In your Podfile, add the pod Accengage-iOS-SDK-Extension to your newly created target:

    # Add it to your Podfile
    target 'YOUR_NOTIFICATION_CONTENT_EXTENSION_TARGET' do
        pod 'Accengage-iOS-SDK-Extension', '~> 1.1.0'
    end
  2. Then, update your Cocoapods project:

    $ pod update

Link the AccengageExtension.framework to your newly created target

Then, change the newly created NotificationViewController class in such a way that it inherits from ACCNotificationContentViewController and replace the code created by XCode by the following one:

Objective-C:

 // NotificationViewController.h
#import <AccengageExtension/AccengageExtension.h>

@interface NotificationViewController : ACCNotificationContentViewController
@end
 // NotificationViewController.m
#import "NotificationViewController.h"
#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>

@implementation NotificationViewController
@end

Swift:

import AccengageExtension
import UserNotifications
import UserNotificationsUI

class NotificationViewController: ACCNotificationContentViewController {
}

In the NotificationViewController scene of the newly created file MainInterface.storyboard, delete the default Hello world label.

Finally, in the Info.plist file of the extension, update UNNotificationExtensionCategory to acc_carousel_category

Img

Prevent notification tracking

Sometimes, it might be useful to prevent Push Notifications from performing some tracking in order to improve user experience. For example you might need to avoid displaying web redirections, on top of ads or during splashscreen, respecting user preferences...

Accengage provides you a way to disable such tracking.

You can disable or enable the tracking of Push Notification by changing the value of the suspended property:

Objective-C:

[Accengage push].suspended = YES;

Swift:

Accengage.push().suspended = true

Silent Push Notifications

Silent Push Notifications improves the user experience by giving you a way to wake up your app periodically in order to refresh its data in background.

To enable silent Push Notifications in your Xcode project:

  1. In the Project Navigator, select your project.
  2. In the editor, select your iOS app target.
  3. Select the Capabilities tab.
  4. Enable the Background Modes capability.
  5. Enable the Remote notifications background mode. Img

To enable silent push on the Accengage dashboard, tick the content available checkbox when configuring your push message.

Please bare in mind that APNs treats silent Push Notifications as low priority and may throttle their delivery altogether if the total number becomes excessive. The actual limits are dynamic and can change based on conditions, but try to don't send more than a few notifications per hour.