From 3501de87ccd6b18cb0dee43a081bbcb6a557ac86 Mon Sep 17 00:00:00 2001 From: Shivang Date: Tue, 23 Oct 2018 17:40:17 +0530 Subject: [PATCH 1/3] feat: force-start --- docs/ADVANCED.md | 4 ++++ lib/common/notifications.js | 5 +++++ lib/server/push.api.js | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/docs/ADVANCED.md b/docs/ADVANCED.md index 4a07650..4400dd8 100644 --- a/docs/ADVANCED.md +++ b/docs/ADVANCED.md @@ -436,3 +436,7 @@ Push.Configure({ ``` Each category is a named object, snoozeRule and delete in this case. These names will need to match the ones you send via your payload to APNS if you want the action buttons to be displayed. Each category can have up to three buttons which must be labeled yes, no and maybe (This is strict, it will not work if you label them anything other than this). In turn each of these buttons has four properties, callback the javascript function you want to call, title the label for the button, foreground whether or not to bring your app to the foreground and destructive which doesn’t actually do anything destructive, it just colors the button red as a warning to the user that the action may be destructive. + +## Force Starting App + +When you implement the actionable notifications, you might notice that if the user has force closed his application, then the background actions will not work untill user opens the app the next time (Note: If you have used 'foreground': true, which will restart the app, this is not the intended behaviour for many providers). In this situation, 'forceStart' comes in handy. This will start the app again BUT the application will not be brought to foreground, hence it will not disrupt any task that the user was performing. In order to take advantage of this feature, you will need to be using cordova-android 6.0.0 or higher. If you add force-start: 1 to the data payload the application will be restarted in background even if it was force closed. \ No newline at end of file diff --git a/lib/common/notifications.js b/lib/common/notifications.js index 233f505..ce2021d 100644 --- a/lib/common/notifications.js +++ b/lib/common/notifications.js @@ -19,6 +19,7 @@ var _validateDocument = function(notification) { sound: Match.Optional(String), notId: Match.Optional(Match.Integer), contentAvailable: Match.Optional(Match.Integer), + forceStart: Match.Optional(Match.Integer), apn: Match.Optional({ from: Match.Optional(String), title: Match.Optional(String), @@ -102,6 +103,10 @@ Push.send = function(options) { notification.contentAvailable = options.contentAvailable; } + if (typeof options.forceStart !== 'undefined') { + notification.forceStart = options.forceStart; + } + notification.sent = false; notification.sending = 0; diff --git a/lib/server/push.api.js b/lib/server/push.api.js index 27476a4..16b432e 100644 --- a/lib/server/push.api.js +++ b/lib/server/push.api.js @@ -339,6 +339,14 @@ Push.Configure = function(options) { data.actions = notification.actions; } + //Force Start + if(typeof notification.forceStart !== 'undefined') { + data['force-start'] = notification.forceStart; + } + if(typeof notification.contentAvailable !== 'undefined') { + data['content-available'] = notification.contentAvailable; + } + //var message = new gcm.Message(); var message = new gcm.Message({ collapseKey: notification.from, From c0c6b645c6b04a61fe6c4f12eeb6789aa71d008d Mon Sep 17 00:00:00 2001 From: Shivang Date: Tue, 23 Oct 2018 17:52:30 +0530 Subject: [PATCH 2/3] Force restart requires phonegap-plugin-push version 1.9.0 or higher --- package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.js b/package.js index e2f256e..eafc734 100644 --- a/package.js +++ b/package.js @@ -12,7 +12,7 @@ Npm.depends({ }); Cordova.depends({ - 'phonegap-plugin-push': '1.8.4', // previously 1.6.4 + 'phonegap-plugin-push': '1.9.0', // previously 1.8.4 'cordova-plugin-device': '1.1.3', // previously 1.1.1 }); From fcd344e7394b007a9aefdce54b21e447aeabf803 Mon Sep 17 00:00:00 2001 From: Shivang Kar Date: Tue, 23 Oct 2018 17:59:02 +0530 Subject: [PATCH 3/3] Added example --- docs/ADVANCED.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/ADVANCED.md b/docs/ADVANCED.md index 4400dd8..c6e4e35 100644 --- a/docs/ADVANCED.md +++ b/docs/ADVANCED.md @@ -439,4 +439,25 @@ Each category is a named object, snoozeRule and delete in this case. These names ## Force Starting App -When you implement the actionable notifications, you might notice that if the user has force closed his application, then the background actions will not work untill user opens the app the next time (Note: If you have used 'foreground': true, which will restart the app, this is not the intended behaviour for many providers). In this situation, 'forceStart' comes in handy. This will start the app again BUT the application will not be brought to foreground, hence it will not disrupt any task that the user was performing. In order to take advantage of this feature, you will need to be using cordova-android 6.0.0 or higher. If you add force-start: 1 to the data payload the application will be restarted in background even if it was force closed. \ No newline at end of file +When you implement the actionable notifications, you might notice that if the user has force closed his application, then the background actions will not work untill user opens the app the next time (Note: If you have used 'foreground': true, which will restart the app, this is not the intended behaviour for many providers). In this situation, 'forceStart' comes in handy. This will start the app again BUT the application will not be brought to foreground, hence it will not disrupt any task that the user was performing. In order to take advantage of this feature, you will need to be using cordova-android 6.0.0 or higher. If you add force-start: 1 to the data payload the application will be restarted in background even if it was force closed. + +Example: +```javascript +Push.send({ + "from": 'push', + "title": "Test Notification for Force Start", + "text": "This will forcestart your app.", + "badge": 1, + "notId": 123456, + "query": {}, + "apn": { + "sound": "www/application/app/testApp.wav" + }, + "gcm": { + "sound": "testApp" + }, + "forceStart": 1 +}); +``` + +Note: This is restricted to Android only. In IOS, once the user closes an app, you can not restart it forcefully unlike android.