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 Pega Mobile Client. 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. Pega Mobile Client also supports silent notifications. Silent notifications are delivered to JavaScript in background, without any message being displayed in the notification area. They are delivered to an app regardless of whether the app is in the foreground or in the background. Push payload objects in silent notifications use a different payload structure. They must contain a content-available field. 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 Pega Mobile Client 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 Pega Mobile Client.

You can obtain an instance of the object by using the launchbox.Notifications reference.

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 Pega Mobile Client 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"  
}

Silent push notification JSON objects are structured differently. The alert, sound, badge and category fields are not needed.

For Android:

{  
  c2dm: {  
    content-available: 1  
  },  
  xi-name: "my_pega_app"  
} 

For iOS:

{  
  aps : {  
    content-available: 1
  },  
  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 © 2019 and Confidential to Pegasystems Inc. All rights reserved
Pega Community | Feedback
Advanced...