Cordova PushPlugin不在onNotificationGCM上注册设备并返回regid
我已经用Phonegap 3.4安装了PushPlugin onNotificationGCM案例:registered从未执行,我无法将regid存储在服务器数据库中,并开始发送通知 每当我的应用程序打开时,它就会显示出来Cordova PushPlugin不在onNotificationGCM上注册设备并返回regid,cordova,push-notification,Cordova,Push Notification,我已经用Phonegap 3.4安装了PushPlugin onNotificationGCM案例:registered从未执行,我无法将regid存储在服务器数据库中,并开始发送通知 每当我的应用程序打开时,它就会显示出来 收到DeviceRady事件 注册android 成功好吗 我已经做了: 更改senderid Android-ON的谷歌云消息 已创建服务器密钥(但不应该很重要,因为我不在发送部分) 我是否需要: 安装Google play服务api 我错过了什么 我等了几分
- 收到DeviceRady事件
- 注册android
- 成功好吗
- 更改senderid
- Android-ON的谷歌云消息
- 已创建服务器密钥(但不应该很重要,因为我不在发送部分)
- 安装Google play服务api
- 我错过了什么
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
$(“#应用程序状态ul”).append(“注册->注册->注册:”+e.REGID+“ ”);
我和你也有问题。删除包含html内容的代码行。如果要检索它,请将其存储到sessionStorage/localStorage、console或警报中
我的html删除版本
var pushNotification;
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
console.log("registering android");
window.plugins.pushNotification.register(successHandler, errorHandler, {
"senderID": "xxxxxxxxxxx",
"ecb": "onNotificationGCM"
}); // required!
} else {
console.log("registering iOS");
pushNotification.register(tokenHandler, errorHandler, {
"badge": "true",
"sound": "true",
"alert": "true",
"ecb": "onNotificationAPN"
}); // required!
}
}
// handle APNS notifications for iOS
function onNotificationAPN(e) {
if (e.alert) {
navigator.notification.alert(e.alert);
}
if (e.sound) {
var snd = new Media(e.sound);
snd.play();
}
if (e.badge) {
pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
}
}
// handle GCM notifications for Android
function onNotificationGCM(e) {
navigator.notification.alert(e.event);
switch (e.event) {
case 'registered':
if (e.regid.length > 0) {
navigator.notification.alert(e.regid);
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
console.log("regID = " + e.regid);
sessionStorage.setItem("deviceId",e.regid);
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (e.foreground) {
navigator.notification.alert('--INLINE NOTIFICATION--');
// if the notification contains a soundname, play it.
var my_media = new Media("/android_asset/www/" + e.soundname);
my_media.play();
} else { // otherwise we were launched because the user touched a notification in the notification tray.
if (e.coldstart) navigator.notification.alert('--COLDSTART NOTIFICATION--');
else navigator.notification.alert('--BACKGROUND NOTIFICATION--');
}
navigator.notification.alert(e.payload.message);
navigator.notification.alert('MESSAGE -> MSGCNT: ' + e.payload.msgcnt);
break;
case 'error':
navigator.notification.alert('ERROR -> MSG:' + e.msg);
break;
default:
navigator.notification.alert('EVENT -> Unknown, an event was received and we do not know what it is');
break;
}
}
function tokenHandler(result) {
navigator.notification.alert(result, null, 'Alert', 'OK');
sessionStorage.setItem("deviceId", result);
sessionStorage.setItem("notificationServer", "APNS");
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
}
function successHandler(result) {
navigator.notification.alert(result, null, 'Alert', 'OK');
sessionStorage.setItem("deviceId", result);
sessionStorage.setItem("notificationServer", "GCM");
}
function errorHandler(error) {
navigator.notification.alert(error, null, 'Alert', 'OK');
}
解决了。经过这么多天的搜索,pushplugin或phonegap没有任何问题。这一轮,是手机本身。许多人在android 4.2.2上面临推送通知问题,尤其是s4。它在我的android 4.2.2平板电脑上也不起作用。我不知道whatsapp和facebook是如何做到的,无论它们在哪里都是真正的本地应用程序,所以我相信它们对调试有更多的控制
我是如何解决的。。。首先,我重新设置了出厂设置并安装了相同的应用程序。。它的工作没有任何代码更改!展望未来,我担心4.2.2的问题会再次出现,我已经升级到固件4.3,它现在工作得很好 我用过你的密码。onNotificationGCM registered永远不会被调用。请确保首先将dialog和console phonegap插件安装到项目中。这些是我安装的插件:E:\androidworkspace\pg>phonegap本地插件列表[phonegap]com.phonegap.plugins.PushPlugin[phonegap]org.apache.cordova.console[phonegap]org.apache.cordova.device[phonegap]org.apache.cordova.dialogs[phonegap]org.apache.cordova.splashscreen[phonegap]org.apache.cordova.颤音我需要谷歌播放服务api吗?不需要。您只需在谷歌云中获取项目id。