[英]Push notifications only work when logged out
We've got a phoengap app that receives push notifications. 我们有一个phoengap应用程序,可以接收推送通知。 Got quite a wierd one at the moment, when the user is logged out of the app the push notifications work fine.
此刻,当用户从应用程序注销时,推送通知工作正常。 But when they login, it breaks.
但是当他们登录时,它坏了。
I'm wondering if it's re-registering with GCM/Apple and getting a new ID or something when logged in. 我想知道它是否正在向GCM / Apple重新注册并在登录时获得新的ID或其他信息。
I guess the question is, when should I run the following code. 我想问题是,什么时候应该运行以下代码。 At the moment it runs once the user is logged in. Should I run it once ever and then save the ID and never run the register again?
现在,一旦用户登录,它就会运行。我是否应该运行一次,然后保存ID,然后再也不运行寄存器了?
receivedEvent: function(id) {
var pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(this.successHandler, this.errorHandler,{"senderID":"1019013414678","ecb":"app.onNotificationGCM"});
}
else {
pushNotification.register(this.tokenHandler,this.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
}
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
// iOS
onNotificationAPN: function(event) {
var pushNotification = window.plugins.pushNotification;
console.log("Received a notification! " + event.alert);
console.log("event sound " + event.sound);
console.log("event badge " + event.badge);
console.log("event " + event);
if (event.alert) {
navigator.notification.alert(event.alert);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
},
// Android
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
localStorage.setItem("PushID", e.regid)
updateID();
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model
// of the intermediary push server which must also be reflected in GCMIntentService.java
alert(e.message);
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
It was my mistake. 是我的错 I was running this code every time the app opened and it was giving me a new ID.
每次打开应用程序时,我都在运行此代码,并且为我提供了新的ID。 I just kept the ID i had originally and it seems to have worked.
我只是保留了我原来的ID,而且似乎已经奏效了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.