didFinishLaunchingWithOptions is not equivalent to EnteringForeground, that was a mistake from our side.
If you want an event that is called once as the app starts use: Fuse.Platform.Lifecycle.Started
If you want an event that is called every time the app moves from background to foreground use: Fuse.Platform.EnteringForeground
Fuse.Platform.EnteringForeground is equivalent to the JS Lifecycle.onEnteringForeground event
Don’t use the Uno.Platform.Application events as we are making big changes to the lower levels of Uno right now and I don’t want you to get bitten by those
Fuse.Platform.Lifecycle.Started += OnStarted;
static void OnStarted(Fuse.Platform.ApplicationState newState)
{
debug_log "And here we are!";
}
To be honest though, if you are writing Uno you are probably making a module for JS right? In that case you will have a class like this:
[UXGlobalModule]
public sealed class Foo : NativeModule
{
public Foo()
{
..stuff..
}
}
You can just put your initialization code in the constructor. We will then make sure the constructor is called as the app starts and you don’t have to worry about hooking/unhooking to uno events.
I’ve tried an approach like you suggested, but in fact, the SDK I was trying to port to Fuse (OneSignal push notifications) seems to need the didFinishLaunchingWithOptions method because it expects the launchOptions parameter.
This way, I was able to do it using CocoaPods and “injecting” the code like this:
Hi again fernando,
No, currently we don’t expose the launchOptions in any way (other than the workaround you have used). Maybe we need something akin to startup args from regular desktop apps which would let you get the options. I remember looking into this before and finding it not a good fit but I’ll add launchOptions to our internal wishlist so we can revisit it and maybe find some better solution.
Thanks for writing up your solution and am glad to hear you’ve made progress despite the difficulties.
Hi Fernando,
Just a quick message to say we are going to cache the launchOptions so they will be available from Uno. If all goes to plan they will be available as an ObjC.Object property as Uno.Platform.iOS.Application.LaunchOptions in the next release.
Oo good catch, that was not documented yet. However it has shipped so you should be able to access it from Uno.Platform.iOS.Application.LaunchOptions and as planned it is an ObjC.Object