我使用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!
}
使用武力显示
var push = PushNotification.init(
{ "android": {"senderID": "533867441597", "forceShow": "true"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"
}
});