Plugin API Reference

var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");

// Should be called before pushwoosh.onDeviceReady
document.addEventListener('push-notification', function(event) {
	var notification = event.notification;
	// handle push open here
});

// Initialize Pushwoosh. This will trigger all pending push notifications on start.
pushwoosh.onDeviceReady({
	appid: "XXXXX-XXXXX",
	projectid: "XXXXXXXXXXXXXXX",
	serviceName: "XXXX"
});

pushwoosh.registerDevice(
	function(status) {
		var pushToken = status.pushToken;
    	// handle successful registration here
  },
  function(status) {
    // handle registration error here
  }
);
Functions

onDeviceReady(config)

[android, ios, wp8, windows]
Initializes Pushwoosh plugin and triggers a start push message. Should be called on every app launch.

registerDevice(success, fail)

[android, ios, wp8, windows]
Registers device for push notifications and retreives a push Token.

unregisterDevice(success, fail)

[android, ios, wp8, windows]
Unregisters device from receiving push notifications.

setTags(config, success, fail)

[android, ios, wp8, windows]
Sets tags for the device.

getTags(success, fail)

[android, ios, wp8, windows]
Returns tags for the device including default tags.

getPushToken(success)

[android, ios, wp8, windows]
Returns push token if it is available.

[android, ios, wp8, windows]
Returns Pushwoosh HWID used for communications with Pushwoosh API.

[android, ios, wp8, windows]
Starts geolocation-based push notifications.

[android, ios, wp8, windows]
Stops geolocation-based push notifications.

getRemoteNotificationStatus(callback, error)

[android, ios]
Returns a detailed status of push notification permissions.

[android, ios]
Sets the application icon badge number.

[android, ios]
Returns the application icon badge number.

[android, ios]
Adds value to the application icon badge.

[android, ios]
Returns push notification payload if the app has been started in response to push notification or null.

[android, ios]
Clears launch notification, getLaunchNotification() will return null after this call.

setUserId(userId)

[android, ios]
Sets User indentifier.

postEvent(event, attributes)

[android, ios]
Posts events for In-App Messages.

createLocalNotification(config, success, fail)

[android]
Schedules local notification.

[android]
Clears all pending local notifications created by /createLocalNotification.

[android]
Clears all notifications presented in Android Notification Center.

[android]
Starts beacon tracking.

[android]
Stops beacon tracking.

[android]
Informs plugin that app went to background mode (or vise versa).

[android]
Allows multiple notifications to be displayed in the Android Notification Center.

[android]
Allows only the last notification to be displayed in Android Notification Center.

[android]
Sets default sound as incoming notification chime.

[android]
Sets default vibration mode for incoming push. notifications.

[android]
Turns screen on if notification arrives.

[android]
Enables LED blinking when notification arrives and display is off.

setColorLED(color)

[android]
Sets LED color.

getPushHistory(callback)

[android]
Returns array of push notifications received.

[android]
Clears push history.

[ios]
Clears all local notifications from notification center.

Events

[android, ios]
Push notification receive event.

[android, ios, wp8, windows]
Push notification accept event.

onDeviceReady

PushNotification.prototype.onDeviceReady = function( config )

[android, ios, wp8, windows]
Initializes Pushwoosh plugin and triggers a start push message. Should be called on every app launch.

Parameter
Description

config.appid

Pushwoosh application code.

config.projectid

GCM project number for Android platform.

config.serviceName

MPNS service name for wp8 platform.

// initialize Pushwoosh with projectid: "GOOGLE_PROJECT_NUMBER", appid : "PUSHWOOSH_APP_ID", serviceName : "WINDOWS_PHONE_SERVICE". This will trigger all pending push notifications on start.
pushwoosh.onDeviceReady({
    appid : "XXXXX-XXXXX",
    projectid: "XXXXXXXXXXXXXXX",
    serviceName: "XXXX"
});

registerDevice

PushNotification.prototype.registerDevice = function( success, fail )

[android, ios, wp8, windows]
Registers device for push notifications and retreives a push Token.

Parameter
Description

success

success callback. Push token is passed as “status.pushToken” parameter to this callback

fail

error callback

pushwoosh.registerDevice(
    function(status) {
        alert("Registered with push token: " + status.pushToken);
    },
    function(error) {
        alert("Failed to register: " +  error);
    }
);

unregisterDevice

PushNotification.prototype.unregisterDevice = function(	success, fail	)

[android, ios, wp8, windows]
Unregisters device from receiving push notifications.

Parameter
Description

success

success callback

fail

error callback

setTags

PushNotification.prototype.setTags = function(	config, success, fail	)

[android, ios, wp8, windows]
Sets tags for the device.

Parameters

Parameter
Description

config

object with custom device tags

success

success callback

fail

error callback

// sets tags: “deviceName” with value “hello” and “deviceId” with value 10
pushwoosh.setTags({deviceName:"hello", deviceId:10},
    function() {
        console.warn('setTags success');
    },
    function(error) {
        console.warn('setTags failed');
    }
);

// sets list tags "MyTag" with values (array) "hello", "world"
pushwoosh.setTags({"MyTag":["hello", "world"]});

getTags

PushNotification.prototype.getTags = function(	success, fail	)

[android, ios, wp8, windows]
Returns tags for the device including default tags.

Parameter
Description

success

success callback. Receives tags as parameter

fail

error callback

pushwoosh.getTags(
    function(tags) {
        console.warn('tags for the device: ' + JSON.stringify(tags));
    },
    function(error) {
        console.warn('get tags error: ' + JSON.stringify(error));
    }
);

getPushToken

PushNotification.prototype.getPushToken = function(	success	)

[android, ios, wp8, windows]
Returns push token if it is available. Note that the token also comes in registerDevice function callback.

Parameter
Description

success

getPushToken callback

pushwoosh.getPushToken(
    function(token) {
        console.warn('push token: ' + token);
    }
);

getPushwooshHWID

PushNotification.prototype.getPushwooshHWID = function(	success	)

[android, ios, wp8, windows]
Returns Pushwoosh HWID used for communications with Pushwoosh API.

Parameter
Description

success

getPushwooshHWID callback

pushwoosh.getPushwooshHWID(
    function(token) {
        console.warn('Pushwoosh HWID: ' + token);
    }
);

startLocationTracking

PushNotification.prototype.startLocationTracking = function( success, fail	)

[android, ios, wp8, windows]
Starts geolocation-based push notifications. Geozones are configured in Pushwoosh Control panel.

stopLocationTracking

PushNotification.prototype.stopLocationTracking = function(	success, fail	)

[android, ios, wp8, windows]
Stops geolocation-based push notifications.

getRemoteNotificationStatus

PushNotification.prototype.getRemoteNotificationStatus = function(	callback, error	)

[android, ios]
Returns detailed status of push notification permissions.

Parameter
Description

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

PushNotification.prototype.setApplicationIconBadgeNumber = function(	badgeNumber	)

[android, ios]
Set the application icon badge number.

Parameter
Description

badgeNumber

icon badge number

getApplicationIconBadgeNumber

PushNotification.prototype.getApplicationIconBadgeNumber = function(	callback	)

[android, ios]
Returns application icon badge number.

Parameter
Description

callback

success callback

pushwoosh.getApplicationIconBadgeNumber(function(badge){ alert(badge);} );

addToApplicationIconBadgeNumber

PushNotification.prototype.addToApplicationIconBadgeNumber = function( badgeNumber )

[android, ios]
Adds value to application icon badge.

Parameter
Description

badgeNumber

incremental icon badge number

getLaunchNotification

PushNotification.prototype.getLaunchNotification = function(	callback	)

[android, ios]
Returns push notification payload if the app was started in response to a push notification, or null.

Parameter
Description

callback

success callback

clearLaunchNotification

PushNotification.prototype.clearLaunchNotification = function(	callback	)

[android, ios]
Clears launch notification, getLaunchNotification() will return null after this call.

setUserId

PushNotification.prototype.setUserId = function(	userId	)

[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.

Parameter
Description

userId

user string identifier

postEvent

PushNotification.prototype.postEvent = function( event, attributes )

[android, ios]
Posts events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel.

Parameter
Description

event

event to trigger

attributes

object with additional event attributes

pushwoosh.setUserId("XXXXXX");
pushwoosh.postEvent("buttonPressed", { "buttonNumber" : 4, "buttonLabel" : "banner" });

createLocalNotification

PushNotification.prototype.createLocalNotification = function( config, success, fail )

[android]
Schedules local notification.

Parameter
Description

config.msg

notification message

config.seconds

notification delay in seconds

config.userData

additional data to pass in notification

success

success callback

fail

error callback

pushwoosh.createLocalNotification({msg:"Your pumpkins are ready!", seconds:30, userData:"optional"}

clearLocalNotification

PushNotification.prototype.clearLocalNotification = function()

[android]
Clears all pending local notifications created by createLocalNotification

clearNotificationCenter

PushNotification.prototype.clearNotificationCenter = function()

[android]
Clears all notifications presented in Android Notification Center.

startBeaconPushes


PushNotification.prototype.startBeaconPushes = function( success, fail )

[android]
Starts beacon tracking.

stopBeaconPushes

PushNotification.prototype.stopBeaconPushes = function( success, fail )

[android]
Stops beacon tracking.

setBeaconBackgroundMode

PushNotification.prototype.setBeaconBackgroundMode = function( on, success, fail )

[android]
Informs plugin that app went to background mode (or vise versa). Call when going to background when using beacons.

setMultiNotificationMode

PushNotification.prototype.setMultiNotificationMode = function( success, fail )

[android]
Allows multiple notifications to be displayed in the Android Notification Center.

setSingleNotificationMode

PushNotification.prototype.setSingleNotificationMode = function(	success,
fail	)

[android]
Allows only the last notification to be displayed in Android Notification Center.

setSoundType

PushNotification.prototype.setSoundType = function( type, success, fail )

[android]
Sets default sound for incoming pushes.

Parameter
Description

type

Sound type (0 – default, 1 – no sound, 2 – always)

setVibrateType

PushNotification.prototype.setVibrateType = function(type, success, fail )

[android]
Sets default vibration mode for incoming pushes.

Parameter
Description

type

Vibration type (0 – default, 1 – no vibration, 2 – always)

setLightScreenOnNotification

PushNotification.prototype.setLightScreenOnNotification = function( on, success, fail )

[android]
Turns screen on when notification arrives.

Parameter
Description

on

enable/disable screen unlock (disabled by default)

setEnableLED

PushNotification.prototype.setEnableLED = function( on, success, fail )

[android]
Enables led blinking when notification arrives and display is off.

Parameter
Description

on

enable/disable LED blink (disabled by default)

setColorLED

PushNotification.prototype.setColorLED = function( color, success, fail )

[android]
Sets led color. Use with setEnableLED.

Parameter
Description

color

LED color in ARGB integer format

getPushHistory

PushNotification.prototype.getPushHistory = function(	success	)

[android]
Returns array of received push notifications.

Parameter
Description

success

success callback

pushwoosh.getPushHistory(function(pushHistory) {
    if(pushHistory.length == 0)
        alert("no push history");
    else
        alert(JSON.stringify(pushHistory));
});

pushwoosh.clearPushHistory();

clearPushHistory

PushNotification.prototype.clearPushHistory = function()

[android]
Clears push history.

cancelAllLocalNotifications

PushNotification.prototype.cancelAllLocalNotifications = function( callback )

[ios]
Clears all local notifications from the notification center.

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 properties

Property

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

document.addEventListener('push-receive',
	function(event) {
		var userData = event.notification.userdata;

		if (typeof(userData) != "undefined") {
			// handle custom notification data
			console.warn('user data: ' + JSON.stringify(userData));
		}
	}
);

push-notification

[android, ios, wp8, windows]
Push notification accept event. Is fired when user clicks on push notification.

Foreground notifications

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

document.addEventListener('push-notification',
	function(event) {
		var message = event.notification.message;
		var userData = event.notification.userdata;

		if (typeof(userData) != "undefined") {
			console.warn('user data: ' + JSON.stringify(userData));
		}
	}
);

Event properties

Same as push-receive

Plugin API Reference