Notifications


Purpose

Defines methods that configure push notifications and local notifications and handles all notification related actions:

All notification categories must be registered before scheduling any local notification or registering with the push notification service. They must correspond to notification categories defined in the backend environment. If your backend does not support setting a notification category, push notifications are displayed as plain notifications, with no additional actions.

In order for an initial notification (of launching the app) to be delivered as soon as onLaunchboxLoaded finishes executing, you must subscribe to the onNotificationReceive event in the body of the onLaunchboxLoaded function.

The onNotificationReceive event is delivered when either local or push notification is received by the Hybrid Container. Depending on the notification type, the notification object can contain a LocalNotification instance or push payload in JSON format. Push payload objects differ depending on the device platform. See the Push payload structure section below.

Notification actions are identified by the actionId string, which is available only when a notification is delivered to Hybrid Container as a result of user selecting the notification action. If no observer is registered for the event, an alert with a notification message will be presented in Hybrid Container.

An instance of the Notifications object can be obtained via the launchbox.Notifications reference.

Note

This API transparently emulates the Push Notifications API and Local Notifications API but they have become deprecated. You are therefore encouraged to use the Notifications API.

Module

This object belongs to the Notifications product module.

Methods

Name Return type Description
registerCategory Promise

Registers a notification category.

unregisterCategory Promise

Removes a previously registered notification category based on a given category identifier.

registerForPushNotifications Promise

Registers an app for receiving push notifications.

scheduleLocalNotification Promise

Schedules a local notification in the operating system.

cancelLocalNotification Promise

Cancels a pending local notification based on a given notification identifier.

cancelAllNotifications Promise

Cancels all local notifications in the operating system.

Push payload structure

Push notification JSON objects delivered to Hybrid Container are structured differently depending on the device platform.

For Android:

{  
  c2dm: {  
    title: "Some title",  
    message: "Some message",  
    sound : "default"  
    category : "foo"  
  },  
  xi-name: "my_pega_app"  
} 

For iOS:

{  
  aps : {  
    alert : "Some message",  
    sound : "default",  
    badge : 42  
    category : "foo"  
  },  
  xi-name : "my_pega_app"  
}

Error handling

All promises return plain DOMError populated with appropriate messages. In case of the registerForPushNotifications method, if the user denies showing notifications for the app, a NotificationPermissionError error is returned. Failure to pass a required function argument or correct function argument type results in a JavaScript TypeError being thrown.

Related topics

Public API reference
Legal notice | Copyright © 2017 and Confidential to Pegasystems Inc. All rights reserved
PDN | Feedback
Advanced...