如何在 iPhone 应用程序从保存的状态恢复后立即调用函数?

发布于 2024-11-07 11:11:35 字数 197 浏览 0 评论 0原文

  1. 用户打开了我的应用程序。
  2. 他们按下主页按钮,导致我的应用程序关闭并进入“已保存状态”。
  3. 用户将他的设备用于其他用途。
  4. 用户再次打开我的应用程序,从他离开的地方继续。

在我的代码中,如何检测用户已从保存的状态恢复?是否有我可以附加的特定 iOS4 多任务 NSNotification?

  1. User has my app open.
  2. They hit the home button, resulting in my app closing and going into a "saved state".
  3. Users uses his device for other things.
  4. User opens up my app again, resuming from where he left off.

How, in my code, do I detect that the user has resumed from the saved state? Is there a specific iOS4 multitasking NSNotification that I can attach to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

彩扇题诗 2024-11-14 11:11:35

如果系统在后台终止您的应用程序,您可以使用应用程序委托方法来启动并运行。

如果您的应用没有终止,那么观察 UIApplicationDidEnterBackgroundNotification 通知将会有所帮助。它将允许您执行任何 viewController 特定状态保存和清理。您可以使用它来进行快速清理。即冷冻干燥任何延迟创建的实例变量,以使您的应用程序在处于后台状态时在内存占用方面尽可能小。

注册此通知允许您恢复状态 UIApplicationWillEnterForegroundNotification

不过,请确保您小心地删除作为观察者的对象。

You can use the app delegate methods to get you up and running if the system terminates your app is while it is in the background.

If your app isn't terminated, then observing the UIApplicationDidEnterBackgroundNotification notification will be helpful. It will allow you to do any viewController specific state saving and cleanup. You can use this to do quick clean up. i.e. freeze dry any lazily created instance variables in order to make your app as small as possible in terms of memory foot print while it is in the background state.

Registering for this notification allows you to restore state UIApplicationWillEnterForegroundNotification

Make sure you are careful to remove your object as an observer though.

橙味迷妹 2024-11-14 11:11:35

AppDelegate.m:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"Application did enter background.");
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"Application did become active.");
}

AppDelegate.m:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"Application did enter background.");
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"Application did become active.");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文