Hi everybody. I’ve followed some threads concerning this argument, but still cannot succeed in make Push Notifications work on iOS and Android. The app neither asks me permission to send push notifications…so I think there is something wrong.
This is my code in header of index.html:
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!--NOTIFICATIONS -->
<script>
function initPushwoosh() {
var pushNotification = window.plugins.pushNotification;
if(device.platform == "Android")
{
registerPushwooshAndroid();
}else if(device.platform == "iPhone" || device.platform == "iOS")
{
registerPushwooshIOS();
}
}
This is the content of app.js:
.run(function($ionicPlatform,$rootScope, auth, store, jwtHelper, $location) {
$ionicPlatform.ready(function() {
//initPushwoosh();
document.addEventListener(“deviceready”, initPushwoosh, true);
[…]
And this is the content of PushwooshiOS.js:
function registerPushwooshIOS() {
var pushNotification = window.plugins.pushNotification;
//set push notification callback before we initialize the plugin
document.addEventListener('push-notification', function(event) {
//get the notification payload
var notification = event.notification;
//display alert to the user for example
alert(notification.aps.alert);
//clear the app badge
pushNotification.setApplicationIconBadgeNumber(0);
});
//initialize the plugin
pushNotification.onDeviceReady({pw_appid:"XXXX-XXXX"});
if(!window.localStorage['Pushwoosh']){
//register for pushes
pushNotification.registerDevice(
function(status) {
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
window.localStorage['Pushwoosh'] = true;
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
alert(JSON.stringify(['failed to register ', status]));
}
);
}
//reset badges on app start
pushNotification.setApplicationIconBadgeNumber(0);
}
And this of PushwooshAndroid.js:
function registerPushwooshAndroid() {
var pushNotification = window.plugins.pushNotification;
//initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({ projectid: "XXXX-XXXX", appid : "XXXX-XXXX" });
if(!window.localStorage['Pushwoosh']){
//register for pushes
pushNotification.registerDevice(
function(status) {
var pushToken = status;
console.warn('push token: ' + pushToken);
window.localStorage['Pushwoosh'] = true;
},
function(status) {
console.warn(JSON.stringify(['failed to register ', status]));
}
);
}
}
Where am I wrong?
PS: sorry if I made some mistake in asking the question, I’m new of the forum, I have to lear how to correctly ask questions here (copy/paste code, etc).