【问题标题】:Issues with route change on resume with angularjs and cordova push notifications plugin使用 angularjs 和 cordova 推送通知插件在简历上更改路由的问题
【发布时间】: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


【解决方案1】:

我遇到了同样的问题,并通过在超时中包装位置更改来解决它(有点 hacky):

$timeout(function(){$location.path('/yourPath')},0);

我不知道为什么它可以解决问题(至少对我而言),但我想可能是当您单击通知并在下一个空闲时刻推迟位置更改时,完整的角度功能不可用(超时 0)有帮助。也可能是(附加)应用,$timeout 发送的伎俩......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-02
    • 2016-09-21
    • 2017-03-17
    相关资源
    最近更新 更多