进入Suspended状态后会调用AppDelegate的什么方法?

What method of AppDelegate will be called after entering into Suspended state?

我的应用程序进入后台,如果我再次打开,它会显示我离开它的同一页面。

虽然,如果 iOS 将应用程序置于暂停状态,但它仍在内存中。如果我回来,将调用哪些 AppDelegate 方法。

实际上我的目的是将相同的屏幕从暂停状态恢复到应用程序,如果它没有被终止的话。

最后一件事,如果应用程序从暂停状态返回,将调用 didFinishLaunchWithOptions。?

谢谢..

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (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.
}


- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

didFinishLaunchWithOptions 没打电话。

根据 application's life cycle,当 ios 将您的应用程序置于暂停模式时,您的应用程序将不会收到任何通知。每当您的应用程序进入后台模式时,如果它没有做任何事情 - 不处理 - ios 将把它置于暂停状态。 但是当暂停并且它仍在内存中时,你真的不需要做任何事情来显示你的应用程序之前的屏幕。 ios 自动保持应用程序的状态。仅当您的应用程序在挂起模式下终止时,您才需要管理它......即不在记忆中。

如果您没有使用任何 background execution 方法在后台执行任何操作,如果您收到关于 applicationDidEnterBackground 在某处存储应用程序状态的通知并且 applicationWillEnterForeground 您可以显示已存储状态的应用程序。

或者如果您正在后台执行一些有限的任务,您可以保留局部变量并使用它来跟踪暂停或现在。在 applicationDidEnterBackgroundvariable = inBackground 上,当您完成任务并 variable == inBackground 时,设置 variable == inSuspended 并将您的应用程序状态存储在某处。在 applicationWillEnterForeground

 if  variable  == inSuspended
   {
    //Display app according to previously stored state.
   `variable  == inForgorund`,  
}

您可以使用 AppDelegate 文件中的断点自行测试。

如果用户点击主页按钮一次,应用程序处于挂起状态。 如果用户将点击主页按钮两次,则应用处于非活动状态。

当用户从挂起状态转到应用程序时,我发现了以下方法调用。

首先:applicationWillEnterForeground 然后 applicationDidBecomeActive

didFinishLaunchingWithOptions 未调用。

More details

Apple Documentation所述,

  • application:willFinishLaunchingWithOptions:—This method is your app’s first chance to execute code at launch time.

  • application:didFinishLaunchingWithOptions:—This method allows you to perform any final initialization before your app is displayed to the user.

  • applicationDidBecomeActive:—Lets your app know that it is about to become the foreground app. Use this method for any last minute
    preparation.

  • applicationWillResignActive:—Lets you know that your app is transitioning away from being the foreground app. Use this method to
    put your app into a quiescent state.

  • applicationDidEnterBackground:—Lets you know that your app is now running in the background and may be suspended at any time.

  • applicationWillEnterForeground:—Lets you know that your app is moving out of the background and back into the foreground, but that it is not yet active.

  • applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.

所以 applicationWillEnterForegroundapplicationWillResignActive 将被调用!