从Toast通知启动时,WP8.1 WinJS应用程序崩溃 [英] WP8.1 WinJS application crashes when launched from toast notification

查看:103
本文介绍了从Toast通知启动时,WP8.1 WinJS应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WinJS开发WP8.1应用程序。我正在使用推送通知。我想根据推式通知有效负载中接收的启动字符串执行逻辑。我的吐司通知有效载荷是

I am developing WP8.1 app with WinJS. I am using push notifications. I want to execute a logic depending on "launch" string received in push notification payload. My toast notification payload is

<toast launch='launchString'>
   <visual>
      <binding template='ToastText02'>
         <text id='1'>headlineText</text>
         <text id='2'>bodyText</text>
      </binding>
   </visual>
</toast>

我已经注册了一个活动

WinJS.Application.addEventListener("activated", this.onActivated);

哪个定义为

onActivated: function (args) {

  if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
      if (args.detail.arguments) {
          var launchString = args.detail.arguments;
          eval("angular.element(document.getElementById('mainBody')).scope().onNotification(launchString)")

      }
      else {
          console.log("Not launched from toast notification")
      }
  }
}

这里的onNotification(launchString)函数具有根据launchString做出一些决策的逻辑。

Here onNotification(launchString) function has the logic which makes some decision making based on launchString.

当应用程序处于前台或正在运行时,一切正常在背景中。但是,当应用程序处于终止状态时,我尝试通过点击Toast通知启动应用程序,应用程序在启动后立即崩溃。我无法在VS中进行调试,因为在调试时无法重新创建此方案(因为调试器被杀死时调试器会退出)。

Everything works fine when application is either in foreground or running in background. But when the application is in killed state, and I try to launch by tapping on toast notification, application crashes right after its launched. I am not able to debug this in VS as I could not recreate this scenario while debugging (because debugger exits when a debugging app is killed).


  1. 有什么方法可以调试处于已终止状态的应用程序?

  2. 当应用程序处于终止状态时尝试启动并读取启动参数是什么问题?我该如何解决?

感谢您的帮助!

编辑:
这里是类似的问题。

推荐答案

好,所以我得到了答案。

Ok, so I got my answer.

onActivated 事件在触发cordova deviceready 之前被触发。因此,即使在加载angular.js之前,我的代码也进行了角度调用。因此,由于已加载angular.js,因此应用程序在前景或后台时均能正常运行。为了解决这个问题,我使用了一个超时,并检查 angular 是否是对象

onActivated event was getting fired before cordova deviceready was fired. Hence my code was making a call angular even before angular.js was loaded. Hence application worked fine when it was in foreground or in background as angular.js was already loaded. To solve this I have used a timeout and checked if angular is an object.

onActivated: function (args) {

  if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
      if (args.detail.arguments) {
          var launchString = args.detail.arguments;

          window.setTimeout(function () {
              if(typeof angular !== undefined)
              eval("angular.element(document.getElementById('mainBody')).scope().onNotificationWindows(launchString)");
          }, 3000);

      }
      else {
          console.log("Not launched from toast notification")
      }
  }

}

这篇关于从Toast通知启动时,WP8.1 WinJS应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆