Is applicationWillResignActive ever called before didFinishLaunchingWithOptions ends?

 ̄綄美尐妖づ 提交于 2019-12-18 12:02:26

问题


Can a scenario happen where applicationWillResignActive: will be called before application:didFinishLaunchingWithOptions: ends?

Basically, can I count on application:didFinishLaunchingWithOptions: to always be done before applicationWillResignActive is triggered for the first time?


回答1:


Apple's iOS App Programming Guide in the "App States and Multitasking" Section, indicates applicationWillResignActive: is called as part of your application's handling of events through processing the run loop, which only begins after application:didFinishLaunchingWithOptions: has finished.

Furthermore, application lifecycle events always happen on the main thread, so it wouldn't be possible for one of them to pre-empt the other or run in parallel with each other.




回答2:


Yes -application:didFinishLaunching: will always be called before -applicationWillResignActive:

See this image for more detail:




回答3:


The runloop can be called recursively.

A hypothetical implementation of application:disFinishLaunchigWithOptions: could run the runloop which, in turn, would allow for notification delivery from within the method.

The following contrived example would let the run loop run, yet never return:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    while (YES)
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}


来源:https://stackoverflow.com/questions/16880791/is-applicationwillresignactive-ever-called-before-didfinishlaunchingwithoptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!