我的应用程序进入后台,如果我再次打开,它显示我离开它的同一页面。
虽然,如果iOS将应用程序置于Suspended状态,但它在内存中。如果我回来,将调用哪些AppDelegate方法。
实际上我的目的是将同一个屏幕从暂停状态恢复到应用程序,如果它没有被终止。
最后,如果App从SUSPENDED状态返回,将会调用didFinishLaunchWithOptions吗?
谢谢..
答案 0 :(得分:6)
应用程序:willFinishLaunchingWithOptions: - 此方法是您的应用程序在发布时首次执行代码的机会。
application:didFinishLaunchingWithOptions: - 此方法允许您在应用程序显示之前执行任何最终初始化 用户。
applicationDidBecomeActive: - 让您的应用知道它即将成为前台应用。在最后一刻使用此方法
制备applicationWillResignActive: - 让您知道您的应用正在转变为前景应用。使用此方法来 将您的应用置于静止状态。
applicationDidEnterBackground: - 让您知道您的应用现在正在后台运行,并且可能随时暂停。
applicationWillEnterForeground: - 让您知道您的应用程序正在移出背景并返回到前台,但是 它还没有活跃。
applicationWillTerminate: - 让您知道您的应用已被终止。如果您的应用被暂停,则不会调用此方法。
所以applicationWillEnterForeground
和applicationWillResignActive
会被调用!
答案 1 :(得分:1)
- (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
没有打过电话。
答案 2 :(得分:0)
根据application's life cycle,当ios将您的应用置于暂停模式时,您的应用将不会收到任何通知。每当你的应用程序进入后台模式,如果它没有做任何事情 - 不处理 - ios将把它置于暂停状态。 但是当它被暂停并且仍在内存中时,你真的不需要做任何事情来显示你的应用之前的相同屏幕。 ios自动保持应用程序的状态。只有当您的应用程序在挂起模式下终止时,您才需要对此进行管理。不在记忆中
如果您没有使用任何background execution方法在后台执行任何操作,如果您收到某个地方applicationDidEnterBackground
应用商店状态的通知,则可以考虑处于暂停模式的应用{{1您可以使用存储状态显示应用程序。
或者如果您在后台执行某些有限任务,您可以保留局部变量并使用它来跟踪暂停或现在。在applicationWillEnterForeground
,applicationDidEnterBackground
上,当您完成任务并variable = inBackground
时,设置variable == inBackground
并在某处存储您的应用的状态。在variable == inSuspended
applicationWillEnterForeground
答案 3 :(得分:0)
您可以使用AppDelegate文件中的断点自行测试。
如果用户单击“主页”按钮一次,则app处于暂停状态。 如果用户单击“主页”按钮两次,则应用程序处于非活动状态。
当用户从暂停状态进入应用程序时,我发现了以下方法调用。
首先:applicationWillEnterForeground
然后applicationDidBecomeActive
。
didFinishLaunchingWithOptions
未调用。