您好,感谢您查看此问题,当我的 iOS 应用程序打开时,我无法收到推送通知。但是,当应用程序在后台运行时,它可以完美运行。但是当应用程序打开时,它甚至没有触发应该将通知显示为警报消息的“推送通知”事件。
我遵循了这些说明,但做了一些调整: http ://www.pushwoosh.com/programming-push-notification/ios/ios-additional-platforms/push-notification-sdk-integration-for-phonegap/
这是页面加载时我的代码:
document.addEventListener("deviceready", pushwooshReady, true);
document.addEventListener("push-notification", displayPushwooshMessage, true);
pushwooshReady功能:
function pushwooshReady() {
initPushwoosh();
if(device.platform == 'iOS') {
app.receivedEvent('deviceready');
}
}
initPushwoosh函数:
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();
}
这是 registerPushWooshIOS 函数:
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);
}
这是我的displayPushwooshMessage函数:
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);
}
}
您的帮助将不胜感激。