关于应用进入暂停状态后点击应用图标后应用状态的问题

Questions about app state after tapping on app icon after apps enters suspended state

我正在将应用程序置于后台。

  1. 假设我没有做任何事情来让应用程序在后台保持活动状态,那么应用程序会在 5 秒内进入挂起状态.对吗?

  2. 如果我随后点击应用程序图标会怎样?那不是应该触发 didFinishLaunch 对吗?它只会让我回到上一个屏幕,还会触发 didbecomeActive & willenterforeground 通知。我不会收到任何其他回调。对吗?

  3. 假设 phone 没有重新启动,即使我点击主页然后点击返回应用程序图标之间有几个小时,第 2 点也是正确的。正确的?它是否也坚持设备重启而不是强制重启?
  4. 唯一一次我不会被带回到我所在的屏幕(在回家之前)是如果设备收到内存警告并且我的应用程序被刷新出挂起状态。此时点击应用程序图标将导致 didFinishLaunch。对吗?

(我问这一切是因为 有时 在将应用程序置于后台并再次点击应用程序图标后(例如 10 分钟后),应用程序正在运行现在是启动阶段。大多数时候它只是返回到之前的屏幕)

我已经看过 Will ios terminate the app running in background after a specific time? 但这并没有解决我想要的所有方面。

It will just bring me back to the last screen I was at and also trigger didbecomeActive & willenterforeground notifications.

正确,如果您的应用程序没有在后台终止。

I won't be getting any other callback.

不一定是真的。例如,如果您被本地通知召唤到前线,您也会收到相关事件。

Assuming there is no restart of the phone, point 2 is true even if there are hours between me tapping home and then tapping back the app icon.

不一定。该应用程序可能会在后台静默终止。

Does it also persist device restarts but not force-restart?

绝对不是。设备关闭时应用程序如何运行?关闭应用程序会终止所有应用程序。

I’m asking all of this because sometimes after putting the app in the background and tapping the app icon again (e.g. 10 minutes later), the app is going through it’s launch phase

这不是时间的问题。看门狗进程不断梳理挂起的应用程序,寻找占用过多内存的应用程序,以便其他应用程序可以 运行。如果您是其中之一,您一定不会感到惊讶。

你可以从头开始重新回到前线,也可以从暂停中恢复过来;这是 iOS 应用程序生命中最基本的事实!你只需要接受它。

但是您可以做很多事情来减少在后台被终止的机会。放弃内存消耗对象作为你的后台是第一位的。