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

查看:731
本文介绍了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 vs 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?

另外,我注意到当一个appWillResignActive被调用时收到短信或来电,但用户选择单击确定并继续。我不希望我的应用在这些情况下采取任何行动。我只是希望它继续运行而不进行任何中间清理,因为用户没有退出应用程序。因此,我认为在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:


  • 当app时在 applicationDidBecomeActive:

applicationDidBecomeActive:被调用:

applicationDidBecomeActive: is called:


  • 当应用程序首次在应用程序之后启动时:didFinishLaunchingWithOptions:

  • 之后applicationWillEnterForeground: 如果没有要处理的URL。

  • 应用程序之后:handleOpenURL:是在 applicationWillResignActive: 之后,如果用户忽略了电话或短信等中断,请


  • when app is first launched after application:didFinishLaunchingWithOptions:
  • after applicationWillEnterForeground: if there's no URL to handle.
  • after application:handleOpenURL: is called.
  • after applicationWillResignActive: if user ignores interruption like a phone call or SMS.

applicationWillResignActive:被调用:

applicationWillResignActive: is called:





    • 如果用户接听电话 applicationDidEnterBackground: 被调用。

    • 如果用户忽略呼叫 applicationDidBecomeActive: 被调用。

    • when there is an interruption like a phone call.
      • if user takes call applicationDidEnterBackground: is called.
      • if user ignores call applicationDidBecomeActive: is called.

      • 暂停正在进行的任务

      • 禁用计时器

      • 暂停游戏

      • 降低OpenGL帧速率

      • pause ongoing tasks
      • disable timers
      • pause a game
      • reduce OpenGL frame rates

      applicationDidEnterBackground:被叫:

      applicationDidEnterBackground: is called:


      • applicationWillResignActive:之后

      • docs说你应该:


        • 发布共享资源

        • 保存用户数据

        • 使计时器无效

        • 保存应用程序状态,以便在应用程序终止时恢复它。

        • 禁用用户界面更新

        • after applicationWillResignActive:
        • docs say you should:
          • release shared resources
          • save user data
          • invalidate timers
          • save app state so you can restore it if app is terminated.
          • disable UI updates

          • 如果你在约5秒内没有返回应用程序终止。

          • beginBackgroundTaskWithExpirationHandler:

          • if you dont return within ~5 seconds the app is terminated.
          • you can ask for more time with beginBackgroundTaskWithExpirationHandler:

          官方文档。

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

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