Skip to content

Commit

Permalink
Merge pull request #352 from Fasal-Tech/master
Browse files Browse the repository at this point in the history
feat: force-start
  • Loading branch information
Morten N.O. Nørgaard Henriksen authored Oct 24, 2018
2 parents edb7fe8 + fcd344e commit 1c42bc7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
25 changes: 25 additions & 0 deletions docs/ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,28 @@ 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.

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.
5 changes: 5 additions & 0 deletions lib/common/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions lib/server/push.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down

0 comments on commit 1c42bc7

Please sign in to comment.