WP8.1 WinJS application crashes when launched from

2019-09-04 15:24发布

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条回答
Explosion°爆炸
2楼-- · 2019-09-04 15:51

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

}

查看更多
登录 后发表回答