0
我使用Pushwoosh在Phonegap中发送通知,但是如果我在应用中,通知不会在Android和iOS的情况下显示。推送通知不显示应用何时打开pushwoosh - Phonegap
我该如何解决这个问题?
我已经经历了几个链接,但一直没能弄清楚。
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!
}
你说的 “不露面” 是什么意思? – shader 2015-02-12 13:47:02
不作为推送通知。如果我把一个正常的JavaScript警报,我收到文本作为警报。 – vini 2015-02-13 06:31:17
这是iOS的默认行为。当您在应用程序中时(应用程序位于前台),推送通知会直接转到应用程序,绕过通知中心。这不能改变。 Android模仿此行为。这可以改变(请在github上提交功能请求)。 – shader 2015-02-15 01:26:51