Interactive notifications

improve this page | report issue

Overview

With interactive notification, when a notification arrives, users can take actions without opening the application. When an interactive notification arrives, the device shows action buttons along with the notification message.

Interactive notifications are supported on devices with iOS version 8 onwards and Android v7.0 (API level 24) onwards. If an interactive notification is sent to an iOS or Android device with earlier versions notification actions are not displayed.

Sending interactive push notification

Prepare the notification and send notification. For more information, see Sending push notifications.

Interactive Notifications are centered around notification actions and grouping of notification actions into categories. Firstly, define the various notification actions that can be offered to the application user. Next, define categories where each category groups one or more notification actions. Most importantly assign a unique identifier for each category. Then, to send Interactive Push Notifications to iOS devices specify the category identifier under MobileFirst Operations Console → [your application] → Push → Send Notifications → iOS custom settings and / or MobileFirst Operations Console → [your application] → Push → Send Notifications → Android custom settings Based on the category identifier, the notification action buttons are displayed on the mobile device. For example:

Setting categories for iOS interactive notifications in the MobileFirst Operations Console

To send interactive notifications to Android devices specify the interactive category identifier under MobileFirst Operations Console → [your application] → Push → Send Notifications → Android custom settings . For example:

Setting categories for iOS interactive notifications in the MobileFirst Operations Console

Handling interactive push notifications in Cordova applications

To receive interactive notifications, follow these steps:

  1. In the main JavaScript, define the registered categories for interactive notification and pass it to device register call MFPPush.registerDevice.

    var options = {
         ios: {
             alert: true,
             badge: true,
             sound: true,     
             categories: [{
                 //Category identifier, this is used while sending the notification.
                 id : "poll", 
    
                 //Optional array of actions to show the action buttons along with the message.    
                 actions: [{
                     //Action identifier
                     id: "poll_ok", 
    
                     //Action title to be displayed as part of the notification button.
                     title: "OK", 
    
                     //Optional mode to run the action in foreground or background. 1-foreground. 0-background. Default is foreground.
                     mode: 1,  
    
                     //Optional property to mark the action button in red color. Default is false.
                     destructive: false,
    
                     //Optional property to set if authentication is required or not before running the action.(Screen lock).
                     //For foreground, this property is always true.
                     authenticationRequired: true
                 },
                 {
                     id: "poll_nok",
                     title: "NOK",
                     mode: 1,
                     destructive: false,
                     authenticationRequired: true
                 }],
                        
                 //Optional list of actions that is needed to show in the case alert. 
                 //If it is not specified, then the first four actions will be shown.
                 defaultContextActions: ['poll_ok','poll_nok'],
    
                 //Optional list of actions that is needed to show in the notification center, lock screen. 
                 //If it is not specified, then the first two actions will be shown.
                 minimalContextActions: ['poll_ok','poll_nok'] 
             }]     
         }
    }
    
  2. Pass the options object while registering device for push notifications.

    MFPPush.registerDevice(options, function(successResponse) {
      		navigator.notification.alert("Successfully registered");
      		enableButtons();
    });  
    

Handling interactive push notifications in native iOS applications

Follow these steps to receive interactive notifications:

  1. Enable the application capability to perform background tasks on receiving the remote notifications. This step is required if some of the actions are background-enabled.
  2. Define registered categories for interactive notifications and pass them as options to MFPPush.registerDevice.

    //define categories for Interactive Push
    let acceptAction = UIMutableUserNotificationAction()
    acceptAction.identifier = "OK"
    acceptAction.title = "OK"
    acceptAction.activationMode = .Foreground
    
    let rejetAction = UIMutableUserNotificationAction()
    rejetAction.identifier = "Cancel"
    rejetAction.title = "Cancel"
    rejetAction.activationMode = .Foreground
    
    let category = UIMutableUserNotificationCategory()
    category.identifier = "poll"
    category.setActions([acceptAction, rejetAction], forContext: .Default)
    
    let categories:Set<UIUserNotificationCategory> = [category]
    
    let options = ["alert":true, "badge":true, "sound":true, "categories": categories]
    
    // Register device
     MFPPush.sharedInstance().registerDevice(options as [NSObject : AnyObject], completionHandler: {(response: WLResponse!, error: NSError!) -> Void in
    
Last modified on October 30, 2019