Register and receive push notifications
This requires phonegap 5.0+ ( current stable v1.0.0 )
phonegap plugin add phonegap-plugin-push
It is also possible to install via repo url directly ( unstable )
phonegap plugin add https://github.com/phonegap/phonegap-plugin-push
- Android
- iOS
- WP8
var push = PushNotification.init({ "android": {"senderID": "12345679"},
"ios": {}, "wp": {"channelName": "12345679"} } );
push.on('registration', function(data) {
// data.registrationId
});
push.on('notification', function(data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.additionalData
});
push.on('error', function(e) {
// e.message
});
Parameter | Description |
---|---|
options |
JSON Object platform specific initialization options. |
- Instance of
PushNotification
.
var push = PushNotification.init({ "android": {"senderID": "12345679"},
"ios": {}, "wp": {"channelName": "12345679"} } );
Parameter | Description |
---|---|
event |
String Name of the event to listen to. See below for all the event names. |
callback |
Function is called when the event is triggered. |
The event registration
will be triggered on each successful registration with the 3rd party push service.
Callback Parameter | Description |
---|---|
data.registrationId |
String The registration ID provided by the 3rd party remote push service. |
push.on('registration', function(data) {
// data.registrationId
});
The event notification
will be triggered each time a push notification is received by a 3rd party push service on the device.
Callback Parameter | Description |
---|---|
data.message |
String The text of the push message sent from the 3rd party service. |
data.title |
String The optional title of the push message sent from the 3rd party service. |
data.count |
Integer The number of messages to be displayed in the badge iOS or message count in the notification shade in Android. |
data.sound |
String The name of the sound file to be played upon receipt of the notification. |
data.additionalData |
JSON Object An optional collection of data sent by the 3rd party push service that does not fit in the above properties. |
push.on('notification', function(data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.additionalData
});
The event error
will trigger when an internal error occurs and the cache is aborted.
Callback Parameter | Description |
---|---|
e |
Error Standard JavaScript error object that describes the error. |
push.on('error', function(e) {
// e.message
});
The unregister method is used when the application no longer wants to receive push notifications.
push.unregister(successHandler, errorHandler);
- There should be no dependency on any other plugins.
- All platforms should use the same API!
npm test
The project uses .editorconfig to define the coding style of each file. We recommend that you install the Editor Config extension for your preferred IDE.
The project uses .jshint to define the JavaScript coding conventions. Most editors now have a JSHint add-on to provide on-save or on-edit linting.
- Install jshint.
- Install jshint.vim.
- Install Package Control
- Restart Sublime
- Type
CMD+SHIFT+P
- Type Install Package
- Type JSHint Gutter
- Sublime -> Preferences -> Package Settings -> JSHint Gutter
- Set
lint_on_load
andlint_on_save
totrue