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).
- Is there any way I can debug an app in killed state?
- 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.
Ok, so I got my answer.
onActivated
event was getting fired before cordovadeviceready
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 ifangular
is anobject
.}