Copy link to clipboard
Copied
Hi,
I'm trying to figure out how to correctly use the delegate class on an iOS application using a Native Extension.
We've got it figured out and working, but we have a few bugs and I'm not sure if we're going about it the wrong way.
Our basic procedure is to create and set the delegate in the ContextInitializer function like this:
g_delegate = [[PushNotificationsAppDelegate alloc] init];
[[UIApplication sharedApplication] setDelegate:g_delegate];
However this causes a few problems:
If we load the extension at app startup (say in the actionscript main class constructor) the application crashes with an error:
[XXXXDelegate _stageLoaded]: unrecognized selector sent to instance)
If we delay the extension load, it initialises and works as expected, however any subsequent calls to FRE functions fail eg:
FREDispatchStatusEventAsync(g_ctx, (uint8_t*)[@"test" UTF8String], (uint8_t*)[@"test" UTF8String]);
will cause the application to crash with error:
[XXXXDelegate notifyASyncMessages]: unrecognized selector sent to instance
Anyone have any ideas?
Is there some default Delegate class implementation that the extension uses that I'm destroying?
Any help will be greatly appreciated!
Cheers
Copy link to clipboard
Copied
Hi mic.archbold, any luck with your issue? actually I am also having same crash and log shows the same "[XXXXDelegate notifyASyncMessages]: unrecognized selector sent to instance" as output. if you have found the issue, then please share, truely appriciate...
Best Wishes,
Sanniv.
Copy link to clipboard
Copied
Hi mic.archbold,
just to update on the issue, I was able to rectify this crash issue by overriding those 2 methods in the delegate class although both are empty implementation. It didn't impact on the app though and didn't crash also...
Hope it helps...
Best Wishes,
Sanniv.
Copy link to clipboard
Copied
Thanks for the help, I'm still working through it but I think the solution lies in runtime injection of methods.
The method you've suggested does get around some of the crashes but it breaks the link between flash and the objc layer, as you're basically destroying the original application delegate.
I'll post something when I've worked through it all.
Cheers
Copy link to clipboard
Copied
Just for people still finding this topic, the solution is to do some objc method swizzling for adding core AppDelegate method.
See this example form Freshplanet ANE.
Copy link to clipboard
Copied
Also when using swizzling you should be aware that ANE's attempting to use the same delegate methods will potentially interfere when using the swizzling method. Generally only the last ANE to perform the swizzle will be the one called as the application delegate.
Copy link to clipboard
Copied
Oh gosh! I wasn't aware of that. I suppose there isn't any way to manage it, unless making only one big ANE per project... ?
Copy link to clipboard
Copied
Yeah it's a common problem with people using multiple ANE's. Of course there are ways around it. We use a Core ANE in the distriqt collection to handle any application delegate level functionality and pass information to other ANE's using a different method.