kony.localnotifications Namespace
The kony.localnotifications
namespace provides your app the ability to create and receive local, on-device notifications that do not rely on off-device information coming across a network. The kony.localnotifications namespace contains the following API elements.
Functions
The kony.localnotifications namespace contains the following functions.
Cancels the specified notifications.
Syntax
kony.localnotifications.cancel(notificationId);
Input Parameters
Parameter | Description |
---|---|
notificationId | An array of notification IDs that selects the notifications to cancel. |
Example
/************************************************************************************* * Function:cancelLocalnotifications() * Description: function is used to cancel local notifications. * Author: Kony *************************************************************************************/ function cancelLocalnotifications(){ notificationIdArray = []; notificationIdArray.push("01"); kony.localnotifications.cancel(notificationIdArray); }
Return Values
None
Platform Availability
- iOS
- Android
Creates a local notification.
Syntax
kony.localnotifications.create(notificationId, datetime, message, title, categoryId, pspConfig);
Input Parameters
Parameter | Description |
---|---|
notificationId | A string that specifies a unique ID for the notification. |
datetime | A string that specifies the date and time when the notification must be triggered. Must follow the unicode date, time, and Timezone pattern. |
message | A string that specifies the message for the notification. |
title | A string that specifies the title for the notification. |
categoryId | A string that specifies the category ID to associate this local notification with, or null in case no actions are to be displayed. |
pspConfig |
An optional JavaScript object containing key-value pairs that set the platform-specific options. Used on iOS platform only. The following keys are supported.
|
Example
/************************************************************************************* * Function:createLocalnotification() * Description: Creates local notifications. * Author: Kony *************************************************************************************/ function createLocalnotification(){ var notificationId = "01"; var date = "05 jan 2017 16:42:00 +0530"; var format = "dd MMM yyyy HH:mm:ss Z"; var message = "Local notification Received"; var title = "Title"; var categoryId ="calendar"; kony.localnotifications.create({ "id": notificationId, "dateTime": { "date": date, "format": format }, "message": message, "title": title, "categoryId": categoryId, "pspConfig":{ "badge":1, "sound": kony.localnotifications.DEFAULT_SOUND } }); }
Return Values
None
Remarks
To play a sound when a notification arrives, your app must specify the sound using the "sound" key in the JavaScript object contained in the pspConfig parameter. Your app must assign a sound file from the app's main bundle. If the sound file is not available or the provided file name is incorrect, it will play a default sound from the system (kony.localnotifications.DEFAULT_SOUND
). To know the see file formats, click here
Platform Availability
Available on
- iOS (The kony.notificationsettings.registerCategory API must be called before the create API for it to work)
- Android
Retrieves the pending local notifications.
Syntax
kony.localnotifications.getNotifications(notificationObjects);
Input Parameters
Parameter | Description |
---|---|
notificationObjects | An optional array of notification objects if there are pending notifications, or an empty array if there are not. This parameter is only used on iOS. |
Example
// iOS Example. The callback function is not used on Android. function callback(arrayOfNotificationObjects) { // Your logic if(arrayOfNotificationObjects.length == 0) { kony.print("No pending notifications");; } } kony.localnotifications.getNotifications(callback);
Return Values
None.
Platform Availability
- iOS
- Android
Associates online and offline callbacks for local notifications.
Syntax
kony.localnotifications.setCallbacks(onlinenotification,offlinenotification);
Input Parameters
Parameter | Description |
---|---|
onlinenotification | A callback function that is invoked when the online notification is triggered. For more information, see the Remarks section below. |
offlineNotification | A callback function that is invoked when the offline notification is triggered. For more information, see the Remarks section below. |
Example
/************************************************************************************* * Function:localNotCallBacks() * Description: Initializes local notifications. * Author: Kony *************************************************************************************/ function localNotCallBacks() { try { kony.localnotifications.setCallbacks({ "offlinenotification": offlinenotification, "onlinenotification": onlinenotification }); } catch (err) { kony.print("Error Code " + err.errorCode + " Message " + err.message); } } /* Notification callback handlers. These are invoked automatically when their respective notifications are fired. */ function offlinenotification(notificationobject, actionid ){ alert("offline notification callback inkvoked"); alert("notification object is :"+JSON.stringify(notificationobject) +" action id is "+actionid); } function onlinenotification(notificationobject,actionid){ alert("onlinenotification notification callback inkvoked"); alert("notification object is :"+JSON.stringify(notificationobject)+" action id is "+actionid); }
Return Values
None
Remarks
The callbacks that this function sets are invoked when notifications are raised by the underlying system. The online notification callback is involved when the application is running. The offline callbacks are invoked when the application is not running. This function should be called inside the post app init
event handler when your app starts.
The callback function in the onlinenotification parameter must have the following signature.
onlineNotificationCallback(actionID,notificationObject);
where actionId is a unique ID for the action, and notificationobject is a JavaScript object that contains platform-specific notification information.
The callback function in the offlinenotification parameter must have the following signature.
offlineNotificationCallback(actionID,notificationObject);
where actionId is a unique ID for the action, and notificationobject is a JavaScript object that contains platform-specific notification information.
Platform Availability
- iOS
- Android