Highlighted

Add code to AppDelegate on iOS

Explorer ,
Oct 24, 2017

Copy link to clipboard

Copied

Hey there!

The lifecycle on iOS calles a function in the AppDelegate when starting the App:

application:didFinishLaunchingWithOptions:

I need to add code to this function.

There is a way to inject (overwrite) functions of the AppDelegate with a native extension as suggested here:

Re: UIApplication Delegate

My issue is that "didFinishLaunchingWithOptions" is called obviously before i could even start a native extension that could overwrite that.

Is there a way on modifying the AppDelegate when building the app? Or any other way i could execute my own code within this function?

Any hint appreciated!

Cheers

seilz

TOPICS
Development

Views

565

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Add code to AppDelegate on iOS

Explorer ,
Oct 24, 2017

Copy link to clipboard

Copied

Hey there!

The lifecycle on iOS calles a function in the AppDelegate when starting the App:

application:didFinishLaunchingWithOptions:

I need to add code to this function.

There is a way to inject (overwrite) functions of the AppDelegate with a native extension as suggested here:

Re: UIApplication Delegate

My issue is that "didFinishLaunchingWithOptions" is called obviously before i could even start a native extension that could overwrite that.

Is there a way on modifying the AppDelegate when building the app? Or any other way i could execute my own code within this function?

Any hint appreciated!

Cheers

seilz

TOPICS
Development

Views

566

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 24, 2017 0
Engaged ,
Oct 24, 2017

Copy link to clipboard

Copied

You say "Or any other way i could execute my own code within this function?"
Do you mean native ANE code or actionscript code?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 24, 2017 0
Explorer ,
Oct 24, 2017

Copy link to clipboard

Copied

Native objective c code, yes.

It's crucual, that i invoke a native iOS framwork at this point in time.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 24, 2017 0
el111 LATEST
Engaged ,
Oct 24, 2017

Copy link to clipboard

Copied

ok.

So you can use method swizzling to override the Application Delegates as per the other thread.

I prefer to use observers instead. This to me is cleaner as you don't override anything. Other ANEs can also observe the same event without conflicts. You are just "listening" to the event.

You can see how I do this here

https://github.com/tuarua/Swift-IOS-ANE#applicationdidfinishlaunching

applicationDidFinishLaunching

The static library contains a predefined +(void)load method in FreMacros.h. This method can safely be declared in different ANEs. It is also called once for each ANE and very early in the launch cycle. In here the SwiftController is inited and onLoad() called. This makes an ideal place to add observers for applicationDidFinishLaunching and any other calls which would normally be added as app delegates, thus removing the restriction of one ANE declaring itself as the "owner".

+(void)load is key here.

Note although you are not calling any code in your ANE from actionscript you can attach and run code in the ANE at launch.
Whilst you may not be using Swift like my project, the methodology is the same.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 24, 2017 0