Announcing PhoneGap Push Plugin version 2.1.0

Simon MacDonald
PhoneGap
Published in
2 min readOct 24, 2017

We’re happy to announce the release of the updated PhoneGap Push plugin which brings support for Android O and cordova-android 6.3.0.

Notification Channels

The biggest change in Android O that affects phonegap-plugin-push is the requirement that a NotificationChannel be set up for any app targeting Android SDK 26 or higher.

Without a NotificationChannel setup any app targeting Android SDK 26+ will not show the notification in the shade.

Now, the push plugin will setup a NotificationChannel for you with a label of PushPluginChannel if you don’t specify one before calling the init method. Which means you don’t need to make any changes to your existing code to target Android O.

The plugin also adds three new static methods that you can call at any time. Even before you make the call to init. These methods are:

listChannels to get an enumeration of all the currently configured channels:

PushNotification.listChannels((channels) => {
for(let channel of channels) {
console.log(`ID: ${channel.id} Description: ${channel.description}`);
}
});

createChannel to create a brand new channel:

PushNotification.createChannel(() => {
console.log('success');
}, () => {
console.log('error');
}, {
id: "testchannel1",
description: "My first test channel",
importance: 3
});

deleteChannel to remove an existing channel:

PushNotification.deleteChannel(() => {
console.log('success');
}, () => {
console.log('error');
}, 'testchannel1');

Action Buttons

People gave us feedback that the action button syntax was confusing and we’ve listened. Now when you want some code to run in response to an action button being clicked you just register an event handler on the push plugin object.

For instance if you setup your action button listeners like so:

const push = PushNotification.init({
"android": {},
"ios": {
"sound": true,
"alert": true,
"badge": true,
"categories": {
"invite": {
"yes": {
"callback": "emailGuests", "title": "Email Guests", "foreground": true, "destructive": false },
"no": {
"callback": "snooze", "title": "Snooze", "foreground": true, "destructive": false }
}
}
}
}});

// data contains the push payload just like a notification event
push.on('emailGuests', (data) => {
console.log('I should email my guests');
});

push.on('snooze', (data) => {
console.log('Remind me later');
});

Android payload

{
"registration_ids": ["my device id"],
"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": "emailGuests", "foreground": true},
{ "icon": "snooze", "title": "SNOOZE", "callback": "snooze", "foreground": false}
]
}
}

iOS payload

{
"aps": {
"alert": "This is a notification that will be displayed ASAP.",
"category": "invite"
},
"notId": "1"
}

Other changes

  • Android O Notification Badges support
  • Use icons in mipmap resource directory on Android
  • Ongoing notifications configurable on Android
  • Remove warning when running on iOS 11 + XCode 9

Contact Us

Your feedback is graciously accepted and appreciated!
Please submit your pull requests and issues here.

--

--

Simon MacDonald
PhoneGap

Father, Software Engineer, Comic Enthusiast, Coffee Lover and Developer 🥑 for @AdobeIO