Javascript PushPlugin寄存器函数不提供regid
我在config.xml中添加了。当我运行应用程序时,它显示警报回调成功!结果=OK,即使手机未连接到互联网,然后我按OK,其他情况都不会发生 onNotificationGCM事件不会激发,因此它永远不会返回regidJavascript PushPlugin寄存器函数不提供regid,javascript,cordova,phonegap-pushplugin,Javascript,Cordova,Phonegap Pushplugin,我在config.xml中添加了。当我运行应用程序时,它显示警报回调成功!结果=OK,即使手机未连接到互联网,然后我按OK,其他情况都不会发生 onNotificationGCM事件不会激发,因此它永远不会返回regid function showAlert(message, title) { if (navigator.notification) { navigator.notification.alert(message, null, title, 'OK');
function showAlert(message, title) {
if (navigator.notification) {
navigator.notification.alert(message, null, title, 'OK');
} else {
alert(title ? (title + ": " + message) : message);
}
}
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
$(document).ready(function () {navigator.splashscreen.hide();});
try {
var pushNotification = window.plugins.pushNotification;
pushNotification.register(successHandler, errorHandler, {"senderID":"659859389520","ecb":"onNotificationGCM"});
} catch (ex) {
showAlert(ex, 'push error');
}
setTimeout(function() {
navigator.splashscreen.hide();
}, 3000);
}
function successHandler(result) {
showAlert('Callback Success! Result = '+result, "Success");
}
function errorHandler(error) {
showAlert(error, "Error");
}
function onNotificationGCM(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
showAlert('registration id = '+e.regid);
}
break;
case 'message':
showAlert('message = '+e.message+' msgcnt = '+e.msgcnt, "Message");
break;
case 'error':
showAlert('GCM error = '+e.msg, "Error");
break;
default:
showAlert('An unknown GCM event has occurred', "Unknown Event");
break;
}
}
在ADB日志中,GCM工作绝对正常。它返回一个regid,但sendJavascript没有调用我的onNotificationGCM函数。因此它不起作用。为什么?我做错了什么
05-22 01:28:27.407:V/PushPlugin21372:sendJavascript:javascript:onNotificationGCM{regid:APb91bG…Sqg4YP,event:registed}解决了问题。在调用onNotificationGCM之前,我正在从index.html重定向到另一个页面。因此,根本没有人叫它 为了测试,我将重定向代码放在了onNotificationGCM中,它工作得非常完美