【发布时间】:2015-10-04 04:05:47
【问题描述】:
在应用恢复时尝试重新路由;真的不知道为什么这不起作用。将出现恢复警报,并且还会出现一个主题 ID。想法?
更多细节:收到通知后,lastMessage 被存储。当应用程序恢复时,会检索相关数据,但 $location.path() 不起作用。对 $location.path 的相同调用在其他地方也有效。
关于通知工厂内部的恢复功能:
function onResumeListener() {
document.addEventListener('resume', function() {
alert("resuming");
var lastMessage;
try {
lastMessage = JSON.parse($window.localStorage.getItem('lastMessage'));
alert(lastMessage.topic_id);
//$location.path("/chat/" + lastMessage.topic_id);
//tried putting route change here as well
} catch (exception) {
alert("failure");
lastMessage = '';
}
$location.path("/chat/" + lastMessage.topic_id);
});
}
收到苹果通知
function onNotificationAPN(e) {
$window.localStorage.setItem('lastMessage', JSON.stringify(e));
$rootScope.$broadcast('push.message', e);
if (e.alert) {}
if (e.sound) {}
if (e.badge) {}
}
关于接收安卓通知
function onNotificationGCM(e) {
$window.localStorage.setItem('lastMessage', JSON.stringify(e));
switch (e.event) {
case 'registered':
localStorage.setItem('deviceId', e.regid);
$rootScope.$broadcast('push.register', e.regid);
break;
case 'message':
//alert('broadcast');
$rootScope.$broadcast('push.message', e);
break;
case 'error':
$log.error('Error event received: ' + e);
break;
default:
$log.error('Unknown event received: ' + e);
break;
}
}
【问题讨论】:
-
您找到解决方案了吗?我遇到了同样的问题
-
我和我的团队终于找到了解决方案,但我不记得具体是什么了。不过不要认为我们使用了超时。
标签: android ios angularjs cordova push-notification