I see Apple in default template use application:didFinishLaunchingWithOptions
: to setup window in appDelegate class. My question is why don't use application:willFinishLaunchingWithOptions
instead. Are there something which can only be done in application:didFinishLaunchingWithOptions
.
Can I use application:willFinishLaunchingWithOptions
to initialize rootViewController.
I still new in IOS, I can understand this might be a stupid question, but any help will be appreciated.
If either method returns false , the URL is not handled. If you do not implement one of the methods, only the return value of the implemented method is considered.
So an app delegate is an object that the application object can use to do certain things like display the first window or view when the app starts up, handle outside notifications or save data when the app goes into the background.
application:willFinishLaunchingWithOptions:
Tells the delegate that the launch process has begun but that state restoration has not yet occurred.
Vs
application:didFinishLaunchingWithOptions:
Tells the delegate that the launch process is almost done and the app is almost ready to run.
So the difference is clearly visible. For details you can follow UIApplicationDelegate
So application:willFinishLaunchingWithOptions is just the very previous event of application:didFinishLaunchingWithOptions
So after having the event application:willFinishLaunchingWithOptions, the next event application:didFinishLaunchingWithOptions will be fired.
So it will definitely depend on you needs but usually both are almost similar and most of the time you may not need to use both of those.
So in usual case you can use application:didFinishLaunchingWithOptions as its the latest event in the similar category.
The docs helpfully dug by @itsazzad tell us that the time between these two events is used to "restore app state".
So it seems pointless to initialise view controllers at the earlier event - because state has not been yet restored - and you don't know which UI to present.
You may be re-launched after kill, and need to immediately skip to mid-work UI scenario.
So my answer is: only initialise UI view controllers on didFinishLaunchingWithOptions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With