After struggling for a few hours, I hope I can find someone who understands this. Nativescript offers support for Application events for Angular + Typescript:
http://docs.nativescript.org/angular/core-concepts/application-management.html
However, I do not understand where I should add these. The example from the website shows the following code:
import application = require("application");
application.on(application.launchEvent, function (args: application.ApplicationEventData) {
if (args.android) {
// For Android applications, args.android is an android.content.Intent class.
console.log("Launched Android application with the following intent: " + args.android + ".");
} else if (args.ios !== undefined) {
// For iOS applications, args.ios is NSDictionary (launchOptions).
console.log("Launched iOS application with options: " + args.ios);
}
});
...
application.start({ moduleName: "main-page" });
How can I use this within my Angular application? To me it feels like this isn't actually code for the Angular version, but perhaps I'm missing something.
I have tried importing the application and adding it the ngOnInit of my main AppComponent:
ngOnInit() {
application.on(application.launchEvent, function (args: application.ApplicationEventData) {
if (args.android) {
// For Android applications, args.android is an android.content.Intent class.
console.log("Alert something"); // : " + args.android + ".");
} else if (args.ios !== undefined) {
// For iOS applications, args.ios is NSDictionary (launchOptions).
console.log("Launched iOS application with options: " + args.ios);
}
console.log('launch detected')
});
console.log('application initiated');
}
Although I do not get any errors, I only get to see the application initiated message. Any idea on how I can use the mentioned android args?
Update: In the end it was much easier than expected, please see the code I used to fix this:
import app = require('application');
import "reflect-metadata";
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {AppComponent} from "./app.component";
app.on(app.launchEvent, function (args: app.ApplicationEventData) {
// on launch code
});
nativeScriptBootstrap(AppComponent);
Thank you for your help!