applicationWillEnterForeground 与 applicationDidBecomeActive、applicationWillResignActive 与 applicationDidEnterBackground [英] applicationWillEnterForeground vs. applicationDidBecomeActive, applicationWillResignActive vs. applicationDidEnterBackground

查看:28
本文介绍了applicationWillEnterForeground 与 applicationDidBecomeActive、applicationWillResignActive 与 applicationDidEnterBackground的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序从后台唤醒并且您希望它准备好使其处于活动状态时,实施哪个委托是合适的?

Which is the proper delegate to implement when an application is waking up from being in the background and you want it to prep it to be active?

applicationWillEnterForeground 与 applicationDidBecomeActive -- 有什么区别?

applicationWillEnterForeground vs applicationDidBecomeActive -- What's the difference?

当应用程序即将进入睡眠状态并且您希望它准备好清理和保存数据时,要实现哪个委托是合适的?

Which is the proper delegate to implement for when an application is going to sleep and you want to prep it to cleanup and save data?

applicationWillResignActive 与 applicationDidEnterBackground -- 有什么区别?

applicationWillResignActive vs. applicationDidEnterBackground -- What's the difference?

此外,我注意到 applicationWillResignActive 在收到短信或来电时被调用,但用户选择单击确定"并继续.在这些情况下,我不希望我的应用程序采取任何措施.我只是希望它在没有任何中间清理的情况下继续运行,因为用户没有退出应用程序.因此,我认为仅在 applicationDidEnterBackground 中进行清理工作更有意义.

Also, I've noticed that applicationWillResignActive gets called when an incoming SMS or call comes in but the user chooses to click Ok and continue. I don't want my app to take any action in these cases. I just want it to keep running without any intermediate cleanup since the user didn't exit the app. So, I would think it makes more sense to do cleanup work just in applicationDidEnterBackground.

我非常感谢您提供关于选择要实施哪些代表以实现起床和入睡以及考虑被短信/电话打断等事件的最佳实践的意见.

I would appreciate your input on best practices to follow on choosing which delegates to implement for waking up and going to sleep as well as considering events like being interrupted by SMS/calls.

谢谢

推荐答案

唤醒即重新启动应用程序(通过跳板、应用程序切换或 URL)applicationWillEnterForeground:叫做.它只在应用准备好使用时执行一次,在被置于后台后,而 applicationDidBecomeActive: 可能在启动后被多次调用.这使得 applicationWillEnterForeground: 非常适合需要在重新启动后进行一次的设置.

When waking up i.e. relaunching an app (either through springboard, app switching or URL) applicationWillEnterForeground: is called. It is only executed once when the app becomes ready for use, after being put into the background, while applicationDidBecomeActive: may be called multiple times after launch. This makes applicationWillEnterForeground: ideal for setup that needs to occur just once after relaunch.

applicationWillEnterForeground: 被调用:

applicationWillEnterForeground: is called:

  • 重新启动应用程序时
  • applicationDidBecomeActive 之前:

applicationDidBecomeActive: 被调用:

applicationDidBecomeActive: is called:

  • 当应用在 application:didFinishLaunchingWithOptions:
  • 之后首次启动时
  • applicationWillEnterForeground 之后: 如果没有要处理的 URL.
  • 在调用 application:handleOpenURL: 之后.
  • applicationWillResignActive之后:如果用户忽略电话或短信等中断.

applicationWillResignActive: 被调用:

applicationWillResignActive: is called:

  • 当有电话之类的中断时.
    • 如果用户接听电话 applicationDidEnterBackground: 被调用.
    • 如果用户忽略调用 applicationDidBecomeActive: 被调用.
    • 暂停正在进行的任务
    • 禁用计时器
    • 暂停游戏
    • 降低 OpenGL 帧速率

    applicationDidEnterBackground: 被调用:

    applicationDidEnterBackground: is called:

    • applicationWillResignActive:
    • 之后
    • 文档说你应该:
      • 释放共享资源
      • 保存用户数据
      • 使计时器无效
      • 保存应用状态,以便在应用终止时恢复它.
      • 禁用界面更新
      • 如果您在大约 5 秒内没有返回,应用将被终止.
      • 您可以使用 beginBackgroundTaskWithExpirationHandler 请求更多时间:

      官方文档.

      这篇关于applicationWillEnterForeground 与 applicationDidBecomeActive、applicationWillResignActive 与 applicationDidEnterBackground的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆