Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin iOS - where does application initialization code go?

I'm building a Xamarin iOS app which uses Ninject (a DI framework). I'm wondering where do I put the code that loads the modules and does the initialization of my application classes?

  • Would I put it in the application's delegate class?
  • In the Main.cs class?
  • In my first ViewController class (which is a menu view so it doesn't really make sens)?

What's the best practice? I can't seem to find it on google.

like image 528
Simon Corcos Avatar asked Jul 12 '26 06:07

Simon Corcos


1 Answers

Due to the fact the UIApplication runloop is created/initialized during the UIApplication construction, I would avoid using the Main entry point as global app initiation point as the app's runloop is not available. Calling any iOS framework members during this phase can led to strange app behavior, crashes, file corruption, etc..

Also any initialization code that hangs (delays) the app at this point will cause the OS to kill your process and any external crash reporting will not happen. Apple's crash reports will be very generic SIGABRT reports.

The UIApplicationDelegate is also created during the UIApplication construction and the FinishedLaunching (application:didFinishLaunchingWithOptions:) delegate method is messaged after the UIApplication, its runloop and UIApplicationDelegate are constructed, but before the UIWindow and root VC are, thus making it the preferred delegate override.

like image 90
SushiHangover Avatar answered Jul 13 '26 23:07

SushiHangover