Hi thanks for viewing this question, I am having trouble receiving my push notification when my iOS app is open. It works perfect when the app is running in the background though. But when the app is open It is not even firing the 'push-notification' event that should display the notification as an alert message.
I followed these instructions, but made a few tweaks: http://www.pushwoosh.com/programming-push-notification/ios/ios-additional-platforms/push-notification-sdk-integration-for-phonegap/
and here is my code when the page loads:
document.addEventListener("deviceready", pushwooshReady, true);
document.addEventListener("push-notification", displayPushwooshMessage, true);
pushwooshReady function:
function pushwooshReady() {
initPushwoosh();
if(device.platform == 'iOS') {
app.receivedEvent('deviceready');
}
}
the initPushwoosh function:
function initPushwoosh() {
//get the plugin
var pushNotification = window.pushNotification;
if(device.platform == 'iOS') {
//call the registration function for iOS
registerPushwooshIOS();
} else if (device.platform == 'Android') {
//call the registration function for Android
registerPushwooshAndroid();
}
pushNotification.onDeviceReady();
}
and this is the registerPushWooshIOS function:
function registerPushwooshIOS() {
var pushNotification = window.pushNotification;
//register for push notifications
pushNotification.registerDevice({alert:true, badge:true, sound:true, pw_appid: PW_appid, appname: PW_appname},
function(status) {
//this is a push token
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
//we are ready to use the plugin methods
onPushwooshiOSInitialized(deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
navigator.notification.alert(JSON.stringify(['failed to register ', status]));
});
//reset badges on application start
pushNotification.setApplicationIconBadgeNumber(0);
}
and here is my displayPushwooshMessage function:
function displayPushwooshMessage(event) {
if(device.platform == 'Android') {
var msg = event.notification.title;
var userData = event.notification.userdata;
if(typeof(userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}
alert(msg);
} else if(device.platform == 'iOS') {
var notification = event.notification;
alert(notification.aps.alert);
pushNotification.setApplicationIconBadgeNumber(0);
}
}
Your help will be very much appreciated.