使用 angularjs 和 cordova 推送通知插件恢复时的路由更改问题
Issues with route change on resume with angularjs and cordova push notifications plugin
在恢复应用程序时尝试重新路由;真的不确定为什么这不起作用。恢复警报出现,主题 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) {}
}
收到 android 条通知后
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;
}
}
我遇到了同样的问题并通过将位置更改包装在超时中解决了它(有点老套):
$timeout(function(){$location.path('/yourPath')},0);
我不知道为什么它解决了问题(至少对我而言),但我想可能是当您单击通知并发布位置时完整的 angular 功能不可用在下一个空闲时刻(超时 0)进行更改会有所帮助。也可能是(附加)适用,$timeout
发送的技巧...
在恢复应用程序时尝试重新路由;真的不确定为什么这不起作用。恢复警报出现,主题 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) {}
}
收到 android 条通知后
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;
}
}
我遇到了同样的问题并通过将位置更改包装在超时中解决了它(有点老套):
$timeout(function(){$location.path('/yourPath')},0);
我不知道为什么它解决了问题(至少对我而言),但我想可能是当您单击通知并发布位置时完整的 angular 功能不可用在下一个空闲时刻(超时 0)进行更改会有所帮助。也可能是(附加)适用,$timeout
发送的技巧...