summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md')
-rw-r--r--StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md817
1 files changed, 238 insertions, 579 deletions
diff --git a/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md b/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md
index 431b5a4e..b446612e 100644
--- a/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md
+++ b/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md
@@ -3,7 +3,6 @@
- [Background Events](#push-message-arrives-with-app-in-background)
- [Tap Events](#user-clicks-on-notification-in-notification-center)
- [Android Behaviour](#android-behaviour)
- - [Notification vs Data Payloads](#notification-vs-data-payloads)
- [Localization](#localization)
- [Images](#images)
- [Sound](#sound)
@@ -16,14 +15,12 @@
- [Priority in Notifications](#priority-in-notifications)
- [Picture Messages](#picture-messages)
- [Background Notifications](#background-notifications)
- - [Use of content_available: true](#use-of-content-available-true)
- - [Caching](#caching)
+ - [Use of content-available: true](#use-of-content-available-true)
- [Huawei and Xiaomi Phones](#huawei-and-xiaomi-phones)
- [Application force closed](#application-force-closed)
- [Visibility](#visibility-of-notifications)
- [Badges](#badges)
- [Support for Twilio Notify](#support-for-twilio-notify)
- - [Notification ID](#notification-id)
- [iOS Behaviour](#ios-behaviour)
- [Sound](#sound-1)
- [Background Notifications](#background-notifications-1)
@@ -70,66 +67,6 @@ Some ways to handle this *double* event are:
# Android Behaviour
-## Notification vs Data Payloads
-
-Notifications behave differently depending on the foreground/background state of the receiving app and the payload you send to the app.
-
-For instance if you send the following payload:
-
-```
-{
- "notification": {
- "title": "Test Notification",
- "body": "This offer expires at 11:30 or whatever",
- "notId": 10
- }
-}
-```
-
-When your app is in the foreground any `on('notification')` handlers you have registered will be called. However if your app is in the background the notification will show up in the system tray. Clicking on the notification in the system tray will start the app but your `on('notification')` handler will not be called as messages with only `notification` payloads will not cause the plugins `onMessageReceived` method to be called.
-
-If you send a payload with a mix of `notification` & `data` objects like this:
-
-```
-{
- "notification": {
- "title": "Test Notification",
- "body": "This offer expires at 11:30 or whatever",
- "notId": 10
- },
- "data" : {
- "surveyID": "ewtawgreg-gragrag-rgarhthgbad"
- }
-}
-```
-
-When your app is in the foreground any `on('notification')` handlers you have registered will be called. If your app is in the background the notification will show up in the system tray. Clicking on the notification in the system tray will start the app and your `on('notification')` handler will not be called as messages with only `notification` payloads will not cause the plugins `onMessageReceived` method to be called.
-
-My recommended format for your push payload when using this plugin (while it differs from Google's docs) works 100% of the time:
-
-```
-{
- "data" : {
- "title": "Test Notification",
- "body": "This offer expires at 11:30 or whatever",
- "notId": 10,
- "surveyID": "ewtawgreg-gragrag-rgarhthgbad"
- }
-}
-```
-
-When your app is in the foreground any `on('notification')` handlers you have registered will be called. If your app is in the background the notification will show up in the system tray. Clicking on the notification in the system tray will start the app and your `on('notification')` handler will be called and the event received by your `on('notification')` handler will get the following data:
-
-```
-{
- "message": "This offer expires at 11:30 or whatever",
- "title": "Test Notification",
- "additionalData": {
- "surveyID": "ewtawgreg-gragrag-rgarhthgbad"
- }
-}
-```
-
## Localization
Plugin supported localization from resources for: title, message and summaryText.
@@ -158,32 +95,22 @@ Or use localization with formatted constants.
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: {"locKey": "push_app_title"},
- message: 'Simple non-localizable text for message!'
- // Constant with formatted params
- // message: {"locKey": "push_message_fox", "locData": ["fox", "dog"]});
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', {"locKey": "push_app_title"});
+message.addData('message', 'Simple non-localizable text for message!');
+// Constant with formatted params
+// message.addData('message', {"locKey": "push_message_fox", "locData": ["fox", "dog"]});
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -202,8 +129,9 @@ By default the icon displayed in your push notification will be your apps icon.
```javascript
var push = PushNotification.init({
"android": {
+ "senderID": "12345679"
},
- "browser": {
+ browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
"ios": {
@@ -226,10 +154,11 @@ In order to get a better user experience you can specify an alternate icon and b
```javascript
var push = PushNotification.init({
"android": {
+ "senderID": "123456789",
"icon": "phonegap",
"iconColor": "blue"
},
- "browser": {
+ browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
"ios": {
@@ -241,8 +170,7 @@ var push = PushNotification.init({
});
```
-Where *icon* is the name of an `.png` image file in the Android `res/drawable` folder. For example: `platforms/android/res/drawable/phonegap.png`
-Writing a hook to describe how to copy an image to the Android `res/drawable` folder is out of scope for this README but there is an [excellent tutorial](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/) that you can copy.
+Where *icon* is the name of an image in the Android *drawables* folder. Writing a hook to describe how to copy an image to the Android *drawables* folder is out of scope for this README but there is an [excellent tutorial](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/) that you can copy.
*iconColor* is one of the supported formats #RRGGBB or #AARRGGBB or one of the following names: 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'. *iconColor* is supported on Android 5.0 and greater.
@@ -252,48 +180,38 @@ Please follow the [Android icon design guidelines](https://www.google.com/design
Additionally, each push can include a large icon which is used to personalize each push. The location of the image may one of three types.
-The first is the `res/drawable` folder in your app. This JSON sent from GCM:
+The first is the *drawables* folder in your app. This JSON sent from GCM:
```javascript
{
"registration_ids": ["my device id"],
"data": {
"title": "Large Icon",
- "message": "Loaded from drawable folder",
+ "message": "Loaded from drawables folder",
"image": "twitter"
}
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Large Icon',
- message: 'Loaded from drawables folder.',
- image: 'twitter'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Large Icon');
+message.addData('message', 'Loaded from drawables folder.');
+message.addData('image', 'twitter');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
-Would look for the *twitter* image in the `res/drawable` folder and produce the following notification.
+Would look for the *twitter* image in the drawables folder and produce the following notification.
![2015-07-24 02 34 41](https://cloud.githubusercontent.com/assets/353180/8866903/2df48028-3190-11e5-8176-fe8b3f7c5aab.png)
@@ -310,35 +228,25 @@ The second is the *assets* folder in your app. This JSON sent from GCM:
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Large Icon',
- message: 'Loaded from assets folder.',
- image: 'www/image/logo.png'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Large Icon');
+message.addData('message', 'Loaded from assets folder.');
+message.addData('image', 'www/image/logo.png');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
-Would look for the *logo.png* file in the assets/www/img folder. Since your apps www folder gets copied into the Android assets folder it is an excellent spot to store the images without needing to write a hook to copy them to the `res/drawable` folder. It produces the following notification.
+Would look for the *logo.png* file in the assets/www/img folder. Since your apps www folder gets copied into the Android assets folder it is an excellent spot to store the images without needing to write a hook to copy them to the *drawables* folder. It produces the following notification.
![2015-07-24 02 20 02](https://cloud.githubusercontent.com/assets/353180/8866901/2df19052-3190-11e5-8c16-a355c59209f3.png)
@@ -356,52 +264,6 @@ The third is the remote *URL*. This JSON sent from GCM:
}
```
-Here is an example using fcm-node that sends the above JSON:
-
-```javascript
-var FCM = require('fcm-node');
-// Replace these with your own values.
-var apiKey = "replace with API key";
-var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Large Icon',
- message: 'Loaded from URL',
- image: 'https://dl.dropboxusercontent.com/u/887989/antshot.png'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
-});
-```
-
-Produces the following notification.
-
-![2015-07-24 02 17 55](https://cloud.githubusercontent.com/assets/353180/8866900/2df0ab06-3190-11e5-9a81-fdb85bb0f5a4.png)
-
-Finally the Material UI guidelines recommend using a circular icon for the large icon if the subject of the image is a person. This JSON sent from GCM:
-
-```javascript
-{
- "registration_ids": ["my device id"],
- "data": {
- "title": "Large Circular Icon",
- "message": "Loaded from URL",
- "image": "https://pbs.twimg.com/profile_images/837060031895896065/VHIQ4oUf_400x400.jpg",
- "image-type": "circle"
- }
-}
-```
-
Here is an example using node-gcm that sends the above JSON:
```javascript
@@ -411,10 +273,9 @@ var apiKey = "replace with API key";
var deviceID = "my device id";
var service = new gcm.Sender(apiKey);
var message = new gcm.Message();
-message.addData('title', 'Large Circular Icon');
+message.addData('title', 'Large Icon');
message.addData('message', 'Loaded from URL');
-message.addData('image', 'https://pbs.twimg.com/profile_images/837060031895896065/VHIQ4oUf_400x400.jpg');
-message.addData('image-type', 'circular');
+message.addData('image', 'https://dl.dropboxusercontent.com/u/887989/antshot.png');
service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
if(err) console.error(err);
else console.log(response);
@@ -423,7 +284,7 @@ service.send(message, { registrationTokens: [ deviceID ] }, function (err, respo
Produces the following notification.
-![screenshot_20170308-214947](https://cloud.githubusercontent.com/assets/353180/23733917/902a4650-0449-11e7-924e-d45a38030c74.png)
+![2015-07-24 02 17 55](https://cloud.githubusercontent.com/assets/353180/8866900/2df0ab06-3190-11e5-9a81-fdb85bb0f5a4.png)
## Sound
@@ -478,31 +339,21 @@ In order for your your notification to play a custom sound you will need to add
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Sound Test',
- message: 'Loaded res/raw',
- soundname: 'test'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Sound Test');
+message.addData('message', 'Loaded res/raw');
+message.addData('soundname', 'test');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -524,30 +375,20 @@ If you want to see multiple notifications in the shade you will need to provide
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Test Push',
- message: 'Push number 1'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Test Push');
+message.addData('message', 'Push number 1');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -563,30 +404,20 @@ Followed by:
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Test Push',
- message: 'Push number 2'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Test Push');
+message.addData('message', 'Push number 2');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -603,31 +434,21 @@ You will only see "Push number 2" in the shade. However, if you send:
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Test Push',
- message: 'Push number 1',
- notId: 1
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Test Push');
+message.addData('message', 'Push number 1');
+message.addData('notId', 1);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -644,31 +465,21 @@ and:
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Test Push',
- message: 'Push number 2',
- notId: 2
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Test Push');
+message.addData('message', 'Push number 2');
+message.addData('notId', 2);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -690,32 +501,22 @@ A better alternative to stacking your notifications is to use the inbox style to
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'My Title',
- message: 'My first message',
- style: 'inbox',
- summaryText: 'There are %n% notifications'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'My Title');
+message.addData('message', 'My first message');
+message.addData('style', 'inbox');
+message.addData('summaryText', 'There are %n% notifications');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -737,32 +538,22 @@ But, if you follow it up with subsequent notifications like:
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'My Title',
- message: 'My second message',
- style: 'inbox',
- summaryText: 'There are %n% notifications'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'My Title');
+message.addData('message', 'My second message');
+message.addData('style', 'inbox');
+message.addData('summaryText', 'There are %n% notifications');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -790,34 +581,24 @@ Your notification can include a maximum of three action buttons. If you wish to
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'AUX Scrum',
- message: 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.',
- actions: [
- { icon: "emailGuests", title: "EMAIL GUESTS", callback: "app.emailGuests", foreground: true},
- { icon: "snooze", title: "SNOOZE", callback: "app.snooze", foreground: false},
- ]
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'AUX Scrum');
+message.addData('message', 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.');
+message.addData('actions', [
+ { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": true},
+ { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false},
+]);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -847,34 +628,24 @@ Your notification can include action buttons. If you wish to include an icon alo
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'AUX Scrum',
- message: 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.',
- actions: [
- { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": false, "inline": true},
- { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false},
- ]
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'AUX Scrum');
+message.addData('message', 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.');
+message.addData('actions', [
+ { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": false, "inline": true},
+ { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false},
+]);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -941,31 +712,21 @@ You can use a Led notifcation and choose the color of it. Just add a `ledColor`
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Green LED',
- message: 'This is my message with a Green LED',
- ledColor: [0, 0, 255, 0]
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Green LED');
+message.addData('message', 'This is my message with a Green LED');
+message.addData('ledColor', [0, 0, 255, 0]);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -984,31 +745,21 @@ You can set a Vibration Pattern for your notifications. Just add a `vibrationPat
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Vibration Pattern',
- message: 'Device should wait for 2 seconds, vibrate for 1 second then be silent for 500 ms then vibrate for 500 ms',
- vibrationPattern: [2000, 1000, 500, 500]
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Vibration Pattern');
+message.addData('message', 'Device should wait for 2 seconds, vibrate for 1 second then be silent for 500 ms then vibrate for 500 ms');
+message.addData('vibrationPattern', [2000, 1000, 500, 500]);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -1027,31 +778,21 @@ You can set a priority parameter for your notifications. This priority value det
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'This is a maximum priority Notification',
- message: 'This notification should appear in front of all others',
- priority: 2
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'This is a maximum priority Notification');
+message.addData('message', 'This notification should appear in front of all others');
+message.addData('priority', 2);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -1074,32 +815,23 @@ Perhaps you want to include a large picture in the notification that you are sen
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Big Picture',
- message: 'This is my big picture message',
- picture: 'http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg',
- summaryText: 'The internet is built on cat pictures'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Big Picture');
+message.addData('message', 'This is my big picture message');
+message.addData('style', 'picture');
+message.addData('picture', 'http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg');
+message.addData('summaryText', 'The internet is built on cat pictures');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -1127,32 +859,22 @@ First the JSON you send from GCM will need to include `"content-available": "1"`
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- "to": deviceID,
- "data": {
- "title": 'Test Push',
- "message": 'Push number 1',
- "info": 'super secret info',
- "content-available": '1'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Test Push');
+message.addData('message', 'Push number 1');
+message.addData('info', 'super secret info');
+message.addData('content-available', '1');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -1169,38 +891,28 @@ or if you want the payload to be delivered directly to your app without anything
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- "to": deviceID,
- "data": {
- "info": 'super secret info',
- "content-available": '1'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('info', 'super secret info');
+message.addData('content-available', '1');
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
If do not want this type of behaviour just omit `"content-available": 1` from your push data and your `on('notification')` event handler will not be called.
-### Use of content_available: true
+### Use of content-available: true
-The [GCM docs](https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json) will tell you to send a data payload of:
+The GCM docs will tell you to send a data payload of:
```javascript
{
@@ -1214,9 +926,9 @@ The [GCM docs](https://developers.google.com/cloud-messaging/http-server-ref#dow
}
```
-Where the `content_available` property is part of the main payload object. Setting the property in this part of the payload will result in the PushPlugin not getting the data correctly. Setting `content_available: true` will cause the Android OS to handle the push payload for you and not pass the data to the PushPlugin.
+Where the `content-available` property is part of the main payload object. Setting the property in this part of the payload will result in the PushPlugin not getting the data correctly. Setting `content-available: true` will cause the Android OS to handle the push payload for you and not pass the data to the PushPlugin.
-Instead move `content_available: true` into the `data` object of the payload. The property name changes slightly to use a `-` instead of an `_`. So, `content_available` becomes `content-available` and `true` becomes `1` as per the example below:
+Instead move `content-available: true` into the `data` object of the payload and set it to `1` as per the example below:
```javascript
{
@@ -1235,8 +947,7 @@ Instead move `content_available: true` into the `data` object of the payload. Th
These phones have a particular quirk that when the app is force closed that you will no longer be able to receive notifications until the app is restarted. In order for you to receive background notifications:
- On your Huawei device go to Settings > Protected apps > check "My App" where.
-- On your Xiaomi make sure your phone has the "Auto-start" property enabled for your app.
-- On your Asus make sure your phone has the "Auto-start" property enabled for your app.
+- On your Xiaomi makes sure your phone has the "Auto-start" property enabled for your app.
### Application force closed
@@ -1282,50 +993,24 @@ If you add `force-start: 1` to the data payload the application will be restarte
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- "data": {
- "title": 'Force Start',
- "message": 'This notification should restart the app',
- "force-start": '1'
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Force Start');
+message.addData('message', 'This notification should restart the app');
+message.addData('force-start', 1);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
-### Caching
-
-By default, when a notification arrives and 'content-available' is set to '1', the plugin will try to deliver the data payload even if the app is not running. In that case, the payload is cached and may be delivered when the app is started again. To disable this behavior, you can set a `no-cache` flag in the notification payload. 0: caching enabled (default), 1: caching disabled.
-
-```javascript
-{
- "registration_ids": ["my device id"],
- "data": {
- "title": "Push without cache",
- "message": "When the app is closed, this notification will not be cached",
- "content-available": "1",
- "no-cache": "1"
- }
-}
-```
-
## Visibility of Notifications
You can set a visibility parameter for your notifications. Just add a `visibility` field in your notification. -1: secret, 0: private (default), 1: public. `Secret` shows only the most minimal information, excluding even the notification's icon. `Private` shows basic information about the existence of this notification, including its icon and the name of the app that posted it. The rest of the notification's details are not displayed. `Public` Shows the notification's full content.
@@ -1341,31 +1026,21 @@ You can set a visibility parameter for your notifications. Just add a `visibilit
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'This is a public Notification',
- message: 'You should be able to read this notification on your lock screen',
- visibility: 1
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'This is a public Notification');
+message.addData('message', 'You should be able to read this notification on your lock screen');
+message.addData('visibility', 1);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -1386,31 +1061,21 @@ In order to set the badge number you will need to include the `badge` property i
}
```
-Here is an example using fcm-node that sends the above JSON:
+Here is an example using node-gcm that sends the above JSON:
```javascript
-var FCM = require('fcm-node');
+var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
-var fcm = new FCM(apiKey);
-
-var message = {
- to: deviceID,
- data: {
- title: 'Badge Test',
- message: 'Badges, we don\'t need no stinking badges',
- badge: 7
- }
-};
-
-fcm.send(message, function(err, response){
- if (err) {
- console.log(err);
- console.log("Something has gone wrong!");
- } else {
- console.log("Successfully sent with response: ", response);
- }
+var service = new gcm.Sender(apiKey);
+var message = new gcm.Message();
+message.addData('title', 'Badge Test');
+message.addData('message', 'Badges, we don\'t need no stinking badges');
+message.addData('badge', 7);
+service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
+ if(err) console.error(err);
+ else console.log(response);
});
```
@@ -1448,17 +1113,11 @@ The JSON received by your app will comply with the standards described in the se
Note: "sound" and "soundname" are equivalent and are considered to be the same by the plugin.
-## Notification ID
-
-When setting the notification ID or `notId` please make sure that you are not exceeding the [MAX_INT](https://developer.android.com/reference/java/lang/Integer.html#MAX_VALUE) value for Android. Using a value larger than MAX_INT will throw an exception which will be caught by the plugin and it will use a default value of `0`.
-
-This means you can't use the JavaScript's `Date.getMilliseconds()` or Java's `System.currentTimeMillis()` as they will give you a value greater than MAX_INT.
-
# iOS Behaviour
## Sound
-In order for your notification to play a custom sound you will need to add the files to root of your iOS project. The files must be in the proper format. See the [Local and Remote Notification Programming Guide](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SupportingNotificationsinYourApp.html#//apple_ref/doc/uid/TP40008194-CH4-SW10) for more info on proper file formats and how to convert existing sound files.
+In order for your notification to play a custom sound you will need to add the files to root of your iOS project. The files must be in the proper format. See the [Local and Remote Notification Programming Guide](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6) for more info on proper file formats and how to convert existing sound files.
Then send the follow JSON from APNS: