我正在使用Pushwoosh在Phonegap中发送通知,但是如果我在应用中,则在Android和iOS情况下通知都不会显示。
我如何解决这个问题?
我已经通过了一些链接,但未能弄明白。
function initPushwoosh()
{
var pushNotification = window.plugins.pushNotification;
if (device.platform == "Android")
{
//set push notifications handler
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
if (typeof (userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}
});
//initialize Pushwoosh with projectid: "GOOGLE_PROJECT_NUMBER", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({projectid: "", appid: ""});
//register for pushes
pushNotification.registerDevice(
function(status) {
var pushToken = status;
localStorage.setItem("deviceid", pushToken);
console.warn('push token: ' + pushToken);
},
function(status) {
console.warn(JSON.stringify(['failed to register ', status]));
}
);
}
else if (device.platform == "iOS")
{
//set push notification callback before we initialize the plugin
document.addEventListener('push-notification', function(event) {
//get the notification payload
var notification = event.notification;
navigator.notification.alert(notification.aps.alert);
//clear the app badge
pushNotification.setApplicationIconBadgeNumber(0);
});
//initialize the plugin
pushNotification.onDeviceReady({pw_appid: ""});
//register for pushes
pushNotification.registerDevice(
function(status) {
var deviceToken = status['deviceToken'];
localStorage.setItem("deviceid", deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
}
);
//reset badges on app start
pushNotification.setApplicationIconBadgeNumber(0);
}
}
function init()
{
document.addEventListener("deviceready", initPushwoosh, true);
// document.addEventListener("backbutton", onBackKeyDown, false);
// Cordova is ready to be used!
}
答案 0 :(得分:1)
使用force show
var push = PushNotification.init(
{ "android": {"senderID": "533867441597", "forceShow": "true"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"
}
});