OStack程序员社区-中国程序员成长平台

标题: ios - 应用程序在后台保持几分钟后被杀死 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 18:39
标题: ios - 应用程序在后台保持几分钟后被杀死



Best Answer-推荐答案


如果您正确检查了您的应用程序没有崩溃,它会显示在多任务 UI 中,而您不是 executing code in the background ,那么我会说您的应用程序正在被系统终止(由于内存压力或其他原因)。

Apple's documentation提及:

Apps must be prepared for termination to happen at any time and should not wait to save user data or perform other critical tasks. System-initiated termination is a normal part of an app’s life cycle. The system usually terminates apps so that it can reclaim memory and make room for other apps being launched by the user, but the system may also terminate apps that are misbehaving or not responding to events in a timely manner.

Suspended apps receive no notification when they are terminated; the system kills the process and reclaims the corresponding memory. If an app is currently running in the background and not suspended, the system calls the applicationWillTerminate: of its app delegate prior to termination.

所以在您的场景中发生的情况是应用程序进入了暂停状态,并且在一段时间后(您提到的那 5 分钟)应用程序被系统终止了。
看看Background Transition Cycle .

如果您想减少应用程序因内存压力而终止的可​​能性,请查看 What to Do When Your App Enters the Background ,具体来说:

Free up memory as needed. Release any cached data that you do not need and do any simple cleanup that might reduce your app’s memory footprint. Apps with large memory footprints are the first to be terminated by the system, so release image resources, data caches, and any other objects that you no longer need. For more information, see Reduce Your Memory Footprint.

关于ios - 应用程序在后台保持几分钟后被杀死,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35551294/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4