// Change this to the 'Application Code' of your Pushwoosh.com Application var PUSHWOOSH_APPID = "4E1E2-E15E8"; // For Android, we need the 'Project Number' you created at https://console.developers.google.com // While you're there, make sure that 'Google Cloud Messaging for Android' is enabled (menu item API's) var GOOGLE_PROJECT_ID = "408453294312"; (function (global) { app = global.app = global.app || {}; document.addEventListener('deviceready', function () { initPushwoosh(); //window.plugins.pushNotification.unregisterDevice(onSuccess, onError); }, false); })(window); // Pushwoosh code: // TODO de-duplicate; iOS and Android are very similar) function initPushwooshWP8() { var pushNotification = window.plugins.pushNotification; // Set push notification callback before we initialize the plugin. This is called when a push is received. document.addEventListener('push-notification', function (event) { navigator.notification.alert(JSON.stringify(event), null, 'Push received', 'Close'); }); //initialize the plugin pushNotification.onDeviceReady({ appid: PUSHWOOSH_APPID }); } function initPushwooshIOS() { var pushNotification = window.plugins.pushNotification; alert("ttt"); // Set push notification callback before we initialize the plugin. This is called when a push is received. document.addEventListener('push-notification', function (event) { var notification = event.notification; navigator.notification.alert(notification.aps.alert); //to view full push payload navigator.notification.alert(JSON.stringify(notification)); //reset badges on icon pushNotification.setApplicationIconBadgeNumber(0); }); //initialize the plugin pushNotification.onDeviceReady({ pw_appid: PUSHWOOSH_APPID }); Deviceregister(); // reset (hide) badges on start by setting it to 0 pushNotification.setApplicationIconBadgeNumber(0); } Deviceregister = function () { var pushNotification = window.plugins.pushNotification; //alert(pushNotification.registerDevice); pushNotification.registerDevice( function (success) { // not all platforms agree on the result type var token = typeof result === 'string' ? result : result['deviceToken']; alert("success" + token); }, function (fail) { navigator.notification.alert(JSON.stringify(['failed to register ', status])); }); }; function initPushwooshAndroid() { var pushNotification = window.plugins.pushNotification; // Set push notification callback before we initialize the plugin. This is called when a push is received. document.addEventListener('push-notification', function (event) { var title = event.notification.title; var userData = event.notification.userdata; if (typeof (userData) != "undefined") { navigator.notification.alert('user data: ' + JSON.stringify(userData)); } navigator.notification.alert(title); }); // This will trigger all pending push notifications on start. pushNotification.onDeviceReady({ projectid: GOOGLE_PROJECT_ID, appid: PUSHWOOSH_APPID }); } function initPushwoosh() { if (window.navigator.simulator === true) { alert('This plugin is not available in the simulator.'); return; } else if (window.plugins.pushNotification === undefined || typeof window.plugins.pushNotification.onDeviceReady == "undefined") { alert('Plugin not found1 for push. Maybe you are running in AppBuilder Companion app which currently does not support this plugin.'); return; } switch (device.platform) { case "Android": initPushwooshAndroid(); break; case "iPhone": case "iOS": initPushwooshIOS(); break; case "Win32NT": initPushwooshWP8(); break; default: alert('Unsupported push platform: ' + device.platform); } }