Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Enable Push Notifications in a Salesforce Mobile SDK Hybrid App
-
(Android only) If your target platform is Android:
-
Add an entry for androidPushNotificationClientId. In
assets/www/bootconfig.json:
1"androidPushNotificationClientId": "33333344444"This value is the project number of the Google project that is authorized to send push notifications to an Android device.
-
Add an entry for androidPushNotificationClientId. In
assets/www/bootconfig.json:
-
In your callback for cordova.require("com.salesforce.plugin.oauth").getAuthCredentials(),
add the following code:
1cordova.require("com.salesforce.util.push").registerPushNotificationHandler( 2 function(message) { 3 // add code to handle notifications 4 }, 5 function(error) { 6 // add code to handle errors 7 } 8);
Example
This code demonstrates how you might handle messages. The server delivers the
payload in message["payload"].
1function(message) {
2 var payload = message["payload"];
3 if (message["foreground"]) {
4 // Notification is received while the app is in
5 // the foreground
6 // Do something appropriate with payload
7 }
8 if (!message["foreground"]) {
9 // Notification was received while the app was in
10 // the background, and the notification was clicked,
11 // bringing the app to the foreground
12 // Do something appropriate with payload
13 }
14}