WP8.1 WinJS application crashes when launched from toast notification

吃可爱长大的小学妹 提交于 2019-12-13 05:23:20

问题


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>

I have registered an event

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

Which is defined as

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")
      }
  }
}

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

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. Is there any way I can debug an app in killed state?
  2. What is the issue when I try to launch and read "launch" parameter when app is in killed state? How can I solve this?

Thanks for your help!

Edit: Here is a similar issue.


回答1:


Ok, so I got my answer.

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")
      }
  }

}



来源:https://stackoverflow.com/questions/32776118/wp8-1-winjs-application-crashes-when-launched-from-toast-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!