Class to interact with Pushwoosh Push Notifications plugin
forge.internal.addEventListener("pushwoosh.pushReceived",
function (notification) {
alert('push received: ' + notification);
}
);
forge.internal.addEventListener("pushwoosh.registrationSuccess",
function (status) {
log('registered with token: ' + status['deviceToken']);
}
);
forge.internal.addEventListener("pushwoosh.registrationFail",
function (error) {
log('Failed to register: ' + error);
}
);
forge.pushwoosh.onDeviceReady({"pw_appid":"XXXXX-XXXXX", "gcm_id":"XXXXXXXXXXXX"});
forge.pushwoosh.registerDevice();
Expose the native API to javascript
onDeviceReady: function ( |
| ) |
Call this first thing with your Pushwoosh App ID (pw_appid parameter) and Google Project ID for Android (gcm_id parameter)
//initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", gcm_id : "PUSHWOOSH_APP_ID". This will also trigger all pending push notifications on start.
forge.pushwoosh.onDeviceReady({"pw_appid":"XXXXX-XXXXX", "gcm_id":"XXXXXXXXXXXX"});
registerDevice: function ( |
| ) |
Call this to register for push notifications and retreive a push token via callbacks
forge.pushwoosh.registerDevice();
unregisterDevice: function ( |
| ) |
Unregisters device from push notifications
forge.pushwoosh.unregisterDevice();
setTags: function ( |
| ) |
Call this to set tags for the device
sets the following tags: "deviceName" with value "hello" and "deviceId" with value 10
forge.pushwoosh.setTags({tags : {deviceName:"hello", deviceId:10}},
function(status) {
forge.logging.log('setTags success');
},
function(status) {
forge.logging.log('setTags failed');
}
);
//setings list tags "tag1" with values (array) "item1", "item2"
forge.pushwoosh.setTags({tags : {"tag1" : ["item1", "item2"]}},
function (status) {
forge.logging.log('set tags success');
},
function(status) {
forge.logging.log('setTags failed');
}
);
getTags: function ( |
| ) |
Call this to get tags for the device
forge.pushwoosh.getTags(
function (tags) {
log('tags loaded: ' + JSON.stringify(tags));
},
function(status) {
forge.logging.log('getTags failed');
}
);
getPushToken: function ( |
| ) |
Call this to get push token if it is available. Note the token also comes in "pushwoosh.registrationSuccess" function callback.
forge.pushwoosh.getPushToken(
function (token) {
forge.logging.log('token : ' + token);
});
getHWID: function ( |
| ) |
Call this to get Pushwoosh HWID used for communications with Pushwoosh API
forge.pushwoosh.getHWID(
function (hwid) {
forge.logging.log('HWID : ' + hwid);
});
getRemoteNotificationStatus: function ( |
| ) |
iOS only, Call this to get a detailed status of push notification permissions.
Returns array with the following items:
"enabled" | if push notificaions enabled. |
"pushBadge" | badges permission granted. |
"pushAlert" | alert permission granted. |
"pushSound" | sound permission granted. |
setApplicationIconBadgeNumber: function ( |
| ) |
iOS only, Call this to set the application icon badge
forge.pushwoosh.setApplicationIconBadgeNumber({badge:10});
cancelAllLocalNotifications: function ( |
| ) |
iOS only, Call this to clear all notifications from the notification center
setForegroundAlert: function( |
| ) |
Set to true to disable automatic push handing in foreground By default is set to true on iOS and false on Android
forge.pushwoosh.setForegroundAlert({alert:true});
setUserId: function( |
| ) |
Set User indentifier. This could be Facebook ID, username or email, or any other user ID. This allows data and events to be matched across multiple user devices.
postEvent: function( |
| ) |
Post 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 |
forge.pushwoosh.postEvent({event:"buttonPressed", attributes:{ "buttonNumber" : 4, "buttonLabel" : "banner" }});