Cordova Plugin API Reference
API methods to manage push notifications for Cordova project
example
1
var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
2
3
// Should be called before pushwoosh.onDeviceReady
4
document.addEventListener('push-notification', function(event) {
5
var notification = event.notification;
6
// handle push open here
7
});
8
9
// Initialize Pushwoosh. This will trigger all pending push notifications on start.
10
pushwoosh.onDeviceReady({
11
appid: "XXXXX-XXXXX",
12
projectid: "XXXXXXXXXXXXXXX",
13
serviceName: "XXXX"
14
});
15
16
pushwoosh.registerDevice(
17
function(status) {
18
var pushToken = status.pushToken;
19
// handle successful registration here
20
},
21
function(status) {
22
// handle registration error here
23
}
24
);
Copied!

onDeviceReady

1
PushNotification.prototype.onDeviceReady = function( config )
Copied!
[android, ios, wp8, windows] Initializes Pushwoosh plugin and triggers a start push message. Should be called on every app launch.
config.appid – Pushwoosh application code.
config.projectid – GCM project number for Android platform.
config.serviceName – MPNS service name for wp8 platform.
example
1
// initialize Pushwoosh with projectid: "GOOGLE_PROJECT_NUMBER", appid : "PUSHWOOSH_APP_ID", serviceName : "WINDOWS_PHONE_SERVICE". This will trigger all pending push notifications on start.
2
pushwoosh.onDeviceReady({
3
appid : "XXXXX-XXXXX",
4
projectid: "XXXXXXXXXXXXXXX",
5
serviceName: "XXXX"
6
});
Copied!
registerDevice
1
PushNotification.prototype.registerDevice = function( success, fail )
Copied!
[android, ios, wp8, windows] Registers device for push notifications and retrieves a push Token.
success – success callback. Push token is passed as “status.pushToken” parameter to this callback
fail – error callback
example
1
pushwoosh.registerDevice(
2
function(status) {
3
alert("Registered with push token: " + status.pushToken);
4
},
5
function(error) {
6
alert("Failed to register: " + error);
7
}
8
);
Copied!

unregisterDevice

1
PushNotification.prototype.unregisterDevice = function( success, fail )
Copied!
[android, ios, wp8, windows] Unregisters device from receiving push notifications.
success – success callback
fail – error callback

setTags

1
PushNotification.prototype.setTags = function( config, success, fail )
Copied!
[android, ios, wp8, windows] Sets tags for the device.
Parameters
config – object with custom device tags
success – success callback. Push token is passed as “status.pushToken” parameter to this callback
fail – error callback
example
1
// sets tags: “deviceName” with value “hello” and “deviceId” with value 10
2
pushwoosh.setTags({deviceName:"hello", deviceId:10},
3
function() {
4
console.warn('setTags success');
5
},
6
function(error) {
7
console.warn('setTags failed');
8
}
9
);
10
11
// sets list tags "MyTag" with values (array) "hello", "world"
12
pushwoosh.setTags({"MyTag":["hello", "world"]});
Copied!

getTags

1
PushNotification.prototype.getTags = function( success, fail )
Copied!
[android, ios, wp8, windows] Returns tags for the device including default tags.
success – success callback. Receives tags as parameters
fail – error callback
1
pushwoosh.getTags(
2
function(tags) {
3
console.warn('tags for the device: ' + JSON.stringify(tags));
4
},
5
function(error) {
6
console.warn('get tags error: ' + JSON.stringify(error));
7
}
8
);
Copied!

getPushToken

1
PushNotification.prototype.getPushToken = function( success )
Copied!
[android, ios, wp8, windows] Returns push token if it is available. Note that the token also comes in registerDevice function callback.
success – success callback.
1
pushwoosh.getPushToken(
2
function(token) {
3
console.warn('push token: ' + token);
4
}
5
);
Copied!

getPushwooshHWID

1
PushNotification.prototype.getPushwooshHWID = function( success )
Copied!
[android, ios, wp8, windows] Returns Pushwoosh HWID used for communications with Pushwoosh API.
success – getPushwooshHWID callback
1
pushwoosh.getPushwooshHWID(
2
function(token) {
3
console.warn('Pushwoosh HWID: ' + token);
4
}
5
);
Copied!

getRemoteNotificationStatus

1
PushNotification.prototype.getRemoteNotificationStatus = function( callback, error )
Copied!
[android, ios] Returns detailed status of push notification permissions.
callback – success callback. Receives object with following properties:
{ ”enabled” : notificaions enabled flag. ”pushBadge” : badges permission granted. (iOS only) ”pushAlert” : alert permission granted. (iOS only) ”pushSound” : sound permission granted. (iOS only) }
error — error callback

setApplicationIconBadgeNumber

1
PushNotification.prototype.setApplicationIconBadgeNumber = function( badgeNumber )
Copied!
[android, ios] Set the application icon badge number.
badgeNumber – icon badge number

getApplicationIconBadgeNumber

1
PushNotification.prototype.getApplicationIconBadgeNumber = function( callback )
Copied!
[android, ios] Returns application icon badge number.
callback – success callback
1
pushwoosh.getApplicationIconBadgeNumber(function(badge){ alert(badge);} );
Copied!

addToApplicationIconBadgeNumber

1
PushNotification.prototype.addToApplicationIconBadgeNumber = function( badgeNumber )
Copied!
[android, ios] Adds value to application icon badge.
badgeNumber — incremental icon badge number

getLaunchNotification

1
PushNotification.prototype.getLaunchNotification = function( callback )
Copied!
[android, ios] Returns push notification payload if the app was started in response to a push notification, or null.
callback – success callback

clearLaunchNotification

1
PushNotification.prototype.clearLaunchNotification = function( callback )
Copied!
[android, ios] Clears launch notification, getLaunchNotification() will return null after this call.

setUserId

1
PushNotification.prototype.setUserId = function( userId )
Copied!
[android, ios] Sets User indentifier– a Facebook ID, username,email, or any other user ID. This allows data and events to be matched across multiple user devices.
userId – user string identifier

postEvent

1
PushNotification.prototype.postEvent = function( event, attributes )
Copied!
[android, ios] Posts events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel.
event – event to trigger
attributes – object with additional event attributes
1
pushwoosh.setUserId("XXXXXX");
2
pushwoosh.postEvent("buttonPressed", { "buttonNumber" : 4, "buttonLabel" : "banner" });
Copied!

createLocalNotification

1
PushNotification.prototype.createLocalNotification = function( config, success, fail )
Copied!
[android, ios] Schedules local notification.
config.msg – notification message
config.seconds – notification delay in seconds
config.userData – additional data to pass in notification
success – success callback
fail – error callback
1
pushwoosh.createLocalNotification({msg:"Your pumpkins are ready!", seconds:30, userData:{}})
Copied!

clearLocalNotification

1
PushNotification.prototype.clearLocalNotification = function()
Copied!
[android] Clears all pending local notifications created by createLocalNotification

clearNotificationCenter

1
PushNotification.prototype.clearNotificationCenter = function()
Copied!
[android] Clears all notifications presented in Android Notification Center.

setMultiNotificationMode

1
PushNotification.prototype.setMultiNotificationMode = function( success, fail )
Copied!
[android] Allows multiple notifications to be displayed in the Android Notification Center.

setSingleNotificationMode

1
PushNotification.prototype.setSingleNotificationMode = function( success,
2
fail )
Copied!
[android] Allows only the last notification to be displayed in Android Notification Center.

setSoundType

1
PushNotification.prototype.setSoundType = function( type, success, fail )
Copied!
[android] Sets default sound for incoming pushes.
type – Sound type (0 – default, 1 – no sound, 2 – always)

setVibrateType

1
PushNotification.prototype.setVibrateType = function(type, success, fail )
Copied!
[android] Sets default vibration mode for incoming pushes.
type – Vibration type (0 – default, 1 – no vibration, 2 – always)

setLightScreenOnNotification

1
PushNotification.prototype.setLightScreenOnNotification = function( on, success, fail )
Copied!
[android] Turns screen on when notification arrives.
on – enable/disable screen unlock (disabled by default)

setEnableLED

1
PushNotification.prototype.setEnableLED = function( on, success, fail )
Copied!
[android] Enables led blinking when notification arrives and display is off.
on – enable/disable LED blink (disabled by default)

setColorLED

1
PushNotification.prototype.setColorLED = function( color, success, fail )
Copied!
[android] Sets led color. Use with setEnableLED.
color – LED color in ARGB integer format

getPushHistory

1
PushNotification.prototype.getPushHistory = function( success )
Copied!
[android] Returns array of received push notifications.
success – success callback
1
pushwoosh.getPushHistory(function(pushHistory) {
2
if(pushHistory.length == 0)
3
alert("no push history");
4
else
5
alert(JSON.stringify(pushHistory));
6
});
7
8
pushwoosh.clearPushHistory();
Copied!

clearPushHistory

1
PushNotification.prototype.clearPushHistory = function()
Copied!
[android] Clears push history.

cancelAllLocalNotifications

1
PushNotification.prototype.cancelAllLocalNotifications = function( callback )
Copied!
[ios] Clears all local notifications from the notification center.

presentInboxUI

[android, ios] Opens Inbox screen.
1
PushNotification.prototype.presentInboxUI = function()
Copied!

showGDPRConsentUI

[android, ios] A part of The GDPR Compliance solution that shows the GDPR Consent Form, ensuring lawful basis for processing personal data of EU citizens.
Copy
1
PushNotification.prototype.showGDPRConsentUI = function()
Copied!

showGDPRDeletionUI

[android, ios] A part of The GDPR Compliance solution that shows the GDPR Deletion Form, ensuring means to comply with the right to erasure.
1
PushNotification.prototype.showGDPRDeletiontUI = function()
Copied!

setCommunicationEnabled

A binary method enabling/disabling all communication with Pushwoosh. The boolean value is false unsubscribes the device from receiving push notifications and stops in-app messages download. The value true reverses the effect.
1
PushNotification.prototype.setCommunicationEnabled = function(enable, success, fail)
Copied!

removeAllDeviceData

Removes all data about the device.
1
PushNotification.prototype.removeAllDeviceData = function()
Copied!

push-receive

[android, ios] Push notification receive event. Is fired when application receives push notification in foreground or background. Closed applications does not receive this event.
Event propertiesProperty
message – (string) Push notification message
userdata – (object/array) Push notification custom data
onStart – (boolean) Is launch notification
foreground – (boolean) Is notification received in foreground
android – (object) Android specific notification payload
ios – (object) iOS specific notification payload
wp8 – (object) Windows Phone specific notification payload
windows – (object) Windows specific notification payload
1
document.addEventListener('push-receive',
2
function(event) {
3
var userData = event.notification.userdata;
4
5
if (typeof(userData) != "undefined") {
6
// handle custom notification data
7
console.warn('user data: ' + JSON.stringify(userData));
8
}
9
}
10
);
Copied!

Foreground notifications

By default Pushwoosh plugin does not display notifications in the foreground and automatically triggers push-receive event. See plugin customization guide for controlling this behavior.

push-notification

[android, ios, wp8, windows] Push notification accept event. It is fired when user taps the push notification.
1
document.addEventListener('push-notification',
2
function(event) {
3
var message = event.notification.message;
4
var userData = event.notification.userdata;
5
6
if (typeof(userData) != "undefined") {
7
console.warn('user data: ' + JSON.stringify(userData));
8
}
9
}
10
);
Copied!
Event properties
Same as push-receive

additionalAuthorizationOptions

[ios only] Provides additional notification authorization options. Should be called before calling registerDevice.
1
pushwoosh.additionalAuthorizationOptions({
2
"UNAuthorizationOptionCriticalAlert" : 1,
3
"UNAuthorizationOptionProvisional": 0 // set 0 or don't specify the option if you don't want to add it to your app.
4
});
Copied!
Copy link
Contents