• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Add code to AppDelegate on iOS

Explorer ,
Oct 24, 2017 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

730

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
community guidelines
Engaged ,
Oct 24, 2017 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?

Votes

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
community guidelines
Explorer ,
Oct 24, 2017 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.

Votes

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
community guidelines
Engaged ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines