AeroGear Cordova Push Plugin

The AeroGear Cordova Push Plugin is an extension of the standard Cordova Push Plugin the difference is that it’s
that it supports AeroGears UnifiedPush better and that makes that there is less boiler plate to take care of in
your javascript.

Before we start please install Apache Cordova CLI, which is the command
line tool to build, deploy and manage Cordova-based applications.

Make sure you have the 3rd party configuration, required by GCM or APNs:

Done! Your project now contains the AeroGear PushPlugin. For an integration with the UnifiedPush Server open the www folder in your text editor and apply the code from the example below. Afterwards you can execute the project with cordova run <platform>.

Sample Example

There are two ways to register a device in the AeroGear UnifiedPush Server devices registry :

Metrics

Optionally the cordova plugin supports sending metrics to UPS. Metrics can be used to view how many users have used the message to open the app. This can be important information if you want to know how well your messages are received by your application users.

UPS sends an unique ID for every push message by default all we have to do set sendMetricInfo to true in the config to tell the plugin to send this ID back when the user opened the app with the notification.

With this set to true the UPS dashboard will show metrics on how 'successful' your message was

iOS background notification

Sending notifications that contain 'content-availble' on iOS will call the javacript first before launching the app, this will enable you to update the UI or do a silent push (e.g. without an alert) to update the content of your app without the user noticing. After fetching the content you’ll have to 'inform' the os about the result by calling setContentAvailable with either NewData, NoData or Failed AeroGear Push plugin API

Windows

In order for your callback to be called when the user uses the notification to bring the application in foreground, you’ll need to add a page parameter to the message:

"message": {
"windows": {
"page": "cordova"
}
}

The sender will use this to trigger a 'special internal' page within the plugin that will call your javascript callback and parse the user-data. Without this page 'param' the app will come to foreground without invoking the javascript callback like you are used on the other platforms.

Xcode 8 setup

Xcode 8 requires a .entitlements file with a aps-environment key present in order to make the push notifications work.
The plugin includes a Cordova hook that will add that file with the aps-environment key and development value.
To change the value to production you have to provide your own Push.entitlements file. You can pick the example file, change the value to production and put it inside the www folder. It’s values will be copied to the project when cordova prepare ios is run.