voltmx.push Namespace
The voltmx.push namespace provides the following API elements.
Functions
The voltmx.push namespace contains the following functions.
voltmx.push.deRegister
This API allows an application on a device to deregister from Push Notifications. This API takes an empty object as the parameter.
If the deregistration is successful, the platform invokes the onsuccessfulderegistration function. If the deregistration is a failure, the platform invokes the onfailurederegistration function.
Syntax
voltmx.push.deRegister(emptyObject)
Input Parameters
Parameter | Description |
---|---|
emptyObject [Object]- Mandatory | Is an empty Object. |
Example
To deregister from Push Notifications, use the following code snippet:
Return Values
None
Exceptions
The following error codes are applicable to onfailureregistration and onfailurederegistration functions:
- 1402 - Unable to connect to push service - PNS service is not available
- 1403 - Registration failed by PNS - Account related or device restrictions (thrown by push.register() API during an onfailureregistration callback).
- 1404 - Deregistration failed - Unable to close channel or PNS internal error while deregistration (thrown by push.deregister() API during an onfailurederegistration callback).
- 1405 - Duplicate Registration - Actual registration details should be provided? (thrown by voltmx. push.register() API during an onfailureregistration callback)
- 1406 - Platform-specific issue. Full details are available in the errormessage. For example, received payload but payload is in incorrect format.
- An error is thrown if input type is invalid or does not follow the expected structure.
- 102-Invalid input error
API Usage
You must use this API to deregister the application and the device from the Push Notifications service.
Platform Availability
- Android
- iOS
- Windows
- Desktop Web
voltmx.push.register
This API allows you to register the application and the mobile device for Push Notifications. This API takes an object as a parameter (the values in the table differ across platforms).
If the registration is successful, the platform invokes the onsuccessfulregistration function. If the registration is a failure, the platform invokes the onfailureregistration function.
Syntax
voltmx.push.register(configObject)(iOS/Android/Desktop Web/Windows)
Input Parameters
Parameter | Description |
---|---|
configObject [Array] - Mandatory (iOS) | The Array for iOS must contain any or all of the following: 0 - Specifies the Notification type as Badge. 1 - Specifies the Notification type as Sound. 2 - Specifies the Notification type as Alert. |
configObject [Object] - Mandatory (Android) | A Hash table for Android must contain the following key value pairs: senderid - Specifies the project ID of the account registered to use FCM. The projectID is the ID for a created API project. For more information on FCM , refer here. |
configObject [Object] - Mandatory (Desktop Web) | A Hash table for Desktop Web must contain the following key value pairs: senderid - Specifies the sender ID of the registered FCM application. For more information on FCM, click here. publicKey - This is the value that is generated under the key-pair tab for the registered FCM application. |
configObject [Object]- Mandatory (Windows) | The Array for Windows must contain the following key value pairs: enableraw: This is a Boolean parameter and it specifies if the device must receive raw messages or not. The default value is true (you can receive raw messages). If you do not want the device to receive raw messages, set the value to false. enabletile: This is a Boolean parameter and it specifies if the device must receive tile messages or not. The default value is true (you can receive tile messages). If you do not want the device to receive tile messages, set the value to false. enabletoast: This is a Boolean parameter and it specifies if the device must receive toast messages or not. The default value is true (you can receive toast messages). If you do not want the device to receive toast messages, set the value to false. Use the fully qualified domain name (FQDN) as the service name. For authenticated notifications, the FQDN must match the registered certificate’s subject name (the CN attribute). For example, www.contoso.com. |
Example
The following are the examples of this API on various platforms:
Android
The following code snippet uses the senderid to register for Push Notifications:
iOS
The following code snippet uses the notification types to register for Push Notifications:
Desktop Web
Windows
Note: Only network URLs are allowed. MPNS allows only images from trusted domains (registered to MPNS) to be displayed to avoid image policies. There is no such restriction on local images.
Exceptions
The following error codes are applicable to onfailureregistration and onfailurederegistration functions:
- 1402 - Unable to connect to push service - PNS service is not available
- 1403 - Registration failed by PNS - Account related or device restrictions (thrown by push.register() API during an onfailureregistration callback).
- 1405 - Duplicate Registration - Actual registration details should be provided? (thrown by voltmx. push.register() API during an onfailureregistration callback)
- 1406 - Platform-specific issue. Full details are available in the errormessage. For example, received payload but payload is in incorrect format.
- An error is thrown if input type is invalid or does not follow the expected structure.
- 102-Invalid input error
API Usage
You must use this API to register the application and the device for Push Notifications with the Push Notifications service provider.
Platform Availability
- Android
- iOS
- Windows
- Desktop Web
voltmx.push.setCallbacks
When an application on a device registers or deregisters for Push Notifications, or if the device receives a notification, the device executes the function of your choice.
You can specify the functions to be executed for Push Notification in an object of the voltmx.push.setCallbacks API.
Syntax
voltmx.push.setCallbacks(Object)
Input Parameters
Object [Object] - Mandatory
A Hash table has the following key-value pairs:
Key | Description |
---|---|
onsuccessfulregistration [Function] - Mandatory | Specifies the function to be executed when the Push Notifications registration is successful. |
onfailureregistration [Function] - Mandatory | Specifies the function to be executed when the Push Notifications registration fails. |
onlinenotification[Function] | Mandatory for iOS, Android, and Windows. Specifies the function to be executed when the device receives a message when the application is running.The message types for which this function is executed varies. The message type on various platforms are as follows:iOS: Sounds, Alerts, or Badges; Windows: raw or toast. |
offlinenotification [Function] | Mandatory for iOS, Android, and Windows. Specifies the function to be executed when the device receives a message when the application is not running.The message types for which this function is executed varies. The message type for iOS is as follows:iOS: Sounds, Alerts, or Badges |
onsuccessfulderegistration [Function] - Mandatory | Specifies the function to be executed when the Push Notification deregistration is successful. |
onfailurederegistration [Function] | Mandatory for Android, and Windows. Optional for iOS. Specifies the function to be executed when the Push Notification deregistration is a failure. |
offlinecallback [Function] - Mandatory. | Specifies the function to be executed when an action is invoked. payloadactionId [String] - A unique id to identify the action. |
Example
Properties
The voltmx.push.setCallbacks API contains the following property:
defaultRemoteNotificationCallbackBehaviour
This property is used to trigger online and offline notification callbacks based on whether your application is in the background, foreground, or is in an unused (dead) state. The default value of this property is false, and it is available only for the iOS platform.
The following table illustrates when online and offline notification callbacks are triggered depending on the value of the defaultRemoteNotificationCallbackBehaviour
property.
Application Status | When defaultRemoteNotificationCallbackBehaviour is true/yes | When defaultRemoteNotificationCallbackBehaviour is false/no |
---|---|---|
When the application is in the foreground | Online notification callback is triggered | Online notification callback is triggered |
When the application is in the background | Online notification callback is triggered | Offline notification callback is triggered |
When the application is unused (dead state) | Offline notification callback is triggered | Offline notification callback is triggered |
Return Values
None
Exceptions
The following error codes are applicable to onfailureregistration and onfailurederegistration functions:
- 1403 - Registration failed by PNS - Account related or device restrictions (thrown by push.register() API during an onfailureregistration callback).
- 1404 - Deregistration failed - Unable to close channel or PNS internal error while deregistration (thrown by push.deregister() API during an onfailurederegistration callback).
API Usage
You must call this API after the application is launched as this API will not be explicitly called by the user.
Implementation Details
The following are the implementation details of this API:
Based on the status of the registration or deregistration attempt (success or failure) and the state of the application on the device (active or inactive) when the Push Notifications arrive, use the following snippet to call the associated functions:
onsuccessfulregistration
If the registration for Push Notifications is successful, this callback is executed by the underlying platform.
The callback takes string as the parameter.
The following code snippet is an example of the onsuccessfulregistration callback.
Note: If there are spaces in the identifier (device token), you must replace the spaces with an empty string to successfully communicate with the APNS Server.
onfailureregistration
If the registration for Push Notifications is a failure, this callback is executed by the underlying platform.
The callback takes an Object as the parameter.
The following code snippet is an example of the onfailureregistration callback:
onlinenotification
If the device receives a message when the application is running, this callback is executed by the underlying platform.
This callback can be used for silent push notifications, as described in the overview Silent Push Notifications. With silent push notifications, your app can perform operations in the background, such as downloading data from across the Internet, and not interrupt users by displaying notifications about the download.
The callback takes an Object as the parameter.
The following code snippet is an example of the onlinenotification callback:
offlinenotification
If the device receives a message when the application is not running, this callback is executed by the underlying platform.
The callback takes an Object as the parameter.
The following code snippet is an example of the offlinenotification callback:
onsuccessfulderegistration
If the deregistration for Push Notifications is successful, this callback is executed by the underlying platform.
The callback takes string as the parameter.
The following code snippet is an example of the onsuccessfulderegistration callback:
onfailurederegistration
If the deregistration for Push Notifications is a failure, this callback is executed by the underlying platform.
The callback takes an Object as the parameter.
Note: This function is not applicable on iOS platform.
The following code snippet is an example of the onfailurederegistration callback:
Callback
permissionStatusCallback
Specifies the permission status of the resource authorization.
Syntax
permissionStatusCallback(response)
Parameters
Parameter | Description |
---|---|
response | A dictionary that contains the authorization status of the requested resource. This argument contains the following key: status [Constant]Resource status constant that indicates the status of the resource authorization. The possible values for status are as follows:voltmx.application.PERMISSION_GRANTEDvoltmx.application.PERMISSION_DENIED |
Registering the Callback in voltmx.push.setCallbacks API
VoltMX.push.setCallbacks({authorizationCallback:permissionStatusCallback, : : : : : : : : });
Example
Note: This callback is called when you invoke the voltmx.push.register(notificationtypes) API.
Platform Availability
- Android
- iOS
- Windows
- Desktop Web