Salesforce

Sending and Receiving Push Notifications (Magic xpa 2.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

Sending and Receiving Push Notifications

Sending push notifications

After the application is installed on your mobile device, you can send push notifications to your mobile devices.

Android

To send push notifications to devices running your application:

  1. Create a Google API project with the Google Cloud Messaging (GCM) service enabled and retrieve that project number and the API key. To do so, follow the steps in the following link: https://developers.google.com/cloud-messaging/android/client. There is no need to carry out the Next steps section.

After the application is properly configured and installed on your device, you need to get the device ID. The device gets a unique ID from the GCM service when the device registers itself to the GCM service.

  1. To register the device to the GCM, run the following expression: ClientNativeCodeExecute('Push.register','A0',’xxxxx’) Where: xxxxx is the project number you received from the Google API in the first phase. For example: ClientNativeCodeExecute('Push.register','A0', '4815162342').

    Since version: 2.5 Note: In prior versions, this was done by running the following expression: ClientOSEnvGet('device_udf|gcm:xxxxx').

  1. Add logic in your application (usually at the initial program) to execute this code.

  2. After the registration is done, retrieve the device ID from the application using the ClientOSEnvGet('device_udf|getpushid') function.

  3. Add logic in your application (usually after the logon stage) to save the device ID to a database, so then the ID can be used to send messages to the device later on.

You can find a sample program with this code in the Rich Client Samples project as program RNC06.

 

Push notifications can be sent to your device from various 3rd party software packages. You can also send them from a Magic xpa application by sending an HTTP Post request. To do this, evaluate the following expression:

HTTPCall('POST', 'https://android.googleapis.com/gcm/send', '{"registration_ids" : '&Trim(B)&',"data" : {"message" : "' & Trim(C) & '"}}' , 'Content-Type:application/json', 'Authorization: key='&Trim(D))

Where:

  • B is a comma-delimited string of device IDs (such as "AXDSFGFSDSFSGSF")

  • C is the text to be sent (such as 'Hello World ')

  • D is the API key retrieved in the first step (such as 'AfdsSyg5ENO6jxUPQvUpIduydn53DlYiiGPTxUM')

Note: Ports 5228, 5229 and 5230 must be opened on the firewall.

You can find a sample program with this code in the Online and Rich Client Samples projects as programs CN20 and RCN20.

iOS

To send push notifications to devices running your application, you should first:

  1. Define an application on the iOS developer portal.

  2. Create an SSL certificate.

  3. Enable the Apple Push Notification service for this application using the SSL certificate.

To do this, follow the steps in the Creating the SSL Certificate and Keys section on the Apple website.

Refer also to:

After the application is properly configured and installed on your device, you need to get the device ID. The device gets a unique ID from the APN service when the device registers itself to the APN service. When starting the application on the device, the registration process to the APN will start and the device will get an ID. You can retrieve this ID from the application using the ClientOSEnvGet('device_udf|getpushid') function.

You should add logic in your application (usually after the logon stage) to save the device ID to a database, so then the ID can be used to send messages to the device later on.

You can find a sample program with this code in the Rich Client Samples project as program RNC06.

 

Push notifications can be sent to your device from various third-party software packages.

For example:

Note:

You can find a sample program that uses the PushSharp .NET library in the Online and Rich Client Samples projects as programs CN20 and RCN20.

Handling push notifications in the application

When the push notification is received in the device and the user clicks on the notification:

  1. If the application is closed, the application will be launched.

    You can get the push notification message by using the following expression: ClientOSEnvGet('device_udf|getargs')

  2. If the application is opened, the External Event will be raised.

    The push notification message will be available in the event parameter.

    The notification message syntax is "GCM-message:" + the notification message.

Since version:

2.4c

 

Reference
Attachment 
Attachment