I am trying to use the Pushwoosh Push Notifications phonegap build plugin but the registerDevice callbacks never fires on my android device, however the initPushwoosh function DOES fire because I see the alert from the call to alert("initPushwoosh" ) in the code below
Below is my config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.phonegap.hello-world"
version = "1.0.0">
<name>Push notification</name>
<description>
Camera example app.
</description>
<author href="http://phonegap.com" email="[email protected]">
PhoneGap Team
</author>
<preference name="phonegap-version" value="3.3.0" />
<gap:plugin name="org.apache.cordova.core.camera" />
<plugin name="PushNotification"
value="com.pushwoosh.plugin.pushnotifications.PushNotifications" onload="true"/>
<access origin="*.pushwoosh.com" />
</widget>
and here is my index.js, I just am changing the project id and appid to XXXX so that I don't mistakenly reveal too much.
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
alert("onDeviceReady" );
app.initPushwoosh();
app.receivedEvent('deviceready');
},
initPushwoosh: function() {
alert("initPushwoosh" );
var pushNotification = window.plugins.pushNotification;
pushNotification.registerDevice(
{ projectid: "XXX-XXX-XXXX 3", appid : "XXXXX-XXXXX" },
function(status) {
var pushToken = status;
alert('push token: ' + pushToken);
},
function(status) {
alert(JSON.stringify(['failed to register ', status]));
});
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
if (typeof(userData) != "undefined") {
alert('user data: ' + JSON.stringify(userData));
}
navigator.notification.alert(title);
});
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
takePicture: function() {
navigator.camera.getPicture( function( imageURI ) {
alert( imageURI );
},
function( message ) {
alert( message );
},
{
quality: 50,
destinationType: Camera.DestinationType.FILE_URI
});
}
};
any help would be greatly appreciated... thanks!
Cordova has replaced the window.plugins with the function cordova.require() You need to look for the namespace in which the plugin is defined. For pushwoosh it's: "com.pushwoosh.plugins.pushwoosh.PushNotification"
So instead of:
var PushNotification = window.plugins.PushNotification;
try this:
var PushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With