Skip to main content
marchbold
Inspiring
Jan 13, 2012 5:01 AM UTC
Question

UIApplication Delegate

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

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

Known Participant
Dec 15, 2015 11:14 AM UTC

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.

Translate
marchbold
marchboldAuthor
Inspiring
Dec 16, 2015 10:38 PM UTC

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.

Translate
air native extensions // https://airnativeextensions.com
Known Participant
Dec 17, 2015 11:42 AM UTC

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... ?

Translate
Participating Frequently
Jan 17, 2012 9:06 AM UTC

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.

Translate
marchbold
marchboldAuthor
Inspiring
Jan 18, 2012 10:06 AM UTC

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

Translate
air native extensions // https://airnativeextensions.com
Participating Frequently
Jan 16, 2012 5:11 PM UTC

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.

Translate