Example


A snippet below contains JavaScript that makes use of the Notifications API functionality.

window.onLaunchboxLoaded = function() {  
  // To receive the initial notification, attach a handler in onLaunchboxLoaded().  
  launchbox.Notifications.onNotificationReceive.bind(notificationHandler);  

  // Create a category for receiving new mails with Reply and Snooze buttons.  
  var mailCategory = new NotificationCategory('mail');  
  mailCategory.setActions(  
    new NotificationAction('reply', 'Reply'),  
    new NotificationAction('snooze', 'Snooze')  
  );  

  // Categories can be registered at any moment before notification is received.  
  // It doesn't have to be done inside onLaunchboxLoaded().  
  launchbox.Notifications.registerCategory(mailCategory);  

  // Registration can be done at any time, but both Apple and Google recommend doing it on every app start.  
  launchbox.Notifications.registerForPushNotifications()  
    .then(function(token) {  
      ...  
    });  
};  


// Sample handler.  
var notificationHandler = function(type, payload, actionId) {  
  if (actionId === "reply") {  
    ...  
  } else if (actionId === "snooze") {  
    ...  
  }  
};

Related topics

Notifications
Legal notice | Copyright © 2016 and Confidential to Pegasystems Inc. All rights reserved
PDN | Hybrid Container | Feedback
Advanced...