且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS后台模式:在后台运行位置更新后,该应用程序永不终止

更新时间:2023-01-25 09:00:20

是的,这里的所有内容都是预期的。 JD Wooder删除了一个正确链接文档的答案:管理应用程序的生命周期。 通常,不会主动杀死后台iOS应用。只有在需要系统资源时,它们才会被杀死。这是不可预测的,并且该应用通常在发生时不会收到 applicationWillTerminate 消息(因为该应用通常此时未运行,并且不会被唤醒)只是为了杀死它)。您的应用应同时处理冷启动( appDidFinishLaunching )和热启动( applicationDidBecomeActive )。

Yes, everything here is expected. There's a deleted answer from J.D. Wooder that correctly linked the documentation: "Managing Your App's Life Cycle." As a rule, background iOS apps are not proactively killed. They are only killed when system resources are needed. This is unpredictable, and the app typically will not receive a applicationWillTerminate message when it happens (because the app typically is not running at that point, and it won't be woken up just to kill it). Your app should handled both a cold launch (appDidFinishLaunching) and a warm launch (applicationDidBecomeActive).

从头开始重新启动应用程序非常昂贵,因此,如果没有资源压力,iOS宁愿将最近使用的内容保留在内存中。无所事事的应用非常便宜。

Restarting an app from scratch is expensive, so iOS prefers to keep recently used thing in memory if there's no resource pressure. Apps that are doing nothing are very cheap. to keep around.

请注意,iOS 13在杀死后台应用程序方面变得更加积极,而新手机上的大型摄像头正导致内存压力的消除应用也更快,因此不要长时间在后台运行。但这也很正常。

Note that iOS 13 has grown much more aggressive in killing apps in the background, and that the large cameras on new phones are leading to memory pressures that kill apps more quickly as well, so don't get too comfortable with running in the background for a long time. But it's also very normal.