What method is called after 'applicationDidBecomeActive'?

邮差的信 提交于 2019-12-01 09:16:15

According to the iOS App Programming guide:

Returning to the foreground is your app’s chance to restart the tasks that it stopped when it moved to the background. The steps that occur when moving to the foreground are shown in Figure 3-6. The applicationWillEnterForeground: method should undo anything that was done in your applicationDidEnterBackground: method, and the applicationDidBecomeActive: method should continue to perform the same activation tasks that it would at launch time.

Have you tried re-applying your settings in the applicationDidBecomeActive: method instead of the applicationWillEnterForeground: ?

Another thing to consider is working with notifications:

In the applicationDidBecomeActive: or applicationDidBecomeActive: methods of the AppDelegate, you can tell your app delegate to dispatch notifications to your controllers:

- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */

    // Dispatch notification to controllers
    [[NSNotificationCenter defaultCenter] postNotificationName: @"didBecomeActive" 
                                                        object: nil 
                                                      userInfo: nil];
}

Once you have this, the view controller can register for these notifications (in their init method, for example) like so:

[[NSNotificationCenter defaultCenter] addObserver: self 
                                                 selector: @selector(loadSettings) 
                                                     name: @"didBecomeActive" 
                                                   object: nil];

This way, your controller is aware that the app just became active and can execute any method you want.

In this example, you are telling your view controller to execute the loadSettings method when it receives the didBecomeActive notification (which was posted by the app delegate).

I only have an answer as to why a quick stop start of the App will display a black screen, I have no reference only personal experience and observation.

When the App is sent to the background the OS attempts to take a screen shot to use instead of the Default.png. If you start the App before a screenshot is taken and you don't have a Default.png in your project then you will get that.

Still thinking about your actual question.

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