gpt4 book ai didi

iOS 后台传输使用 NSURLSession

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:07 26 4
gpt4 key购买 nike

我对背景有一些疑问。正如我在理论上读到的那样,一旦所有下载都已下载,就会调用 handleEventsForBackgroundURLSession。这不是iOS触发的,还是应用端触发的。此外,每次下载完成后,我会阅读 URLSessionDidFinishEventsForBackgroundURLSession 如果应用程序由于应用程序崩溃或任何其他原因未运行或处于挂起状态,将调用该应用程序是否在内存中。我的假设是,如果应用程序处于挂起状态,则 URLSessionDidFinishEventsForBackgroundURLSession 已实现的下载 Controller 类也不会在内存中。那么谁能解释一下这个后台操作是如何在操作系统级别发生的?我还读到,一旦下载完所有内容,该应用程序就会唤醒。也可以解释一下吗。。

提前致谢。

最佳答案

根据 Apple 的 documentation :

If an iOS app is terminated by the system and relaunched, the app can use the same identifier to create a new configuration object and session and retrieve the status of transfers that were in progress at the time of termination. This behavior applies only for normal termination of the app by the system. If the user terminates the app from the multitasking screen, the system cancels all of the session’s background transfers. In addition, the system does not automatically relaunch apps that were force quit by the user. The user must explicitly relaunch the app before transfers can begin again.

因此,如果应用程序没有被用户终止,但应用程序由于某种原因被终止(例如,如果 iOS 终止它以释放内存),系统将在所有任务完成后唤醒您的应用程序,调用完成处理程序。您的 NSURLSession 后台任务(下载和上传)在操作系统守护进程中运行,而不是在应用程序进程中运行,因此即使应用程序被 iOS 终止,它们也会继续运行。

关于iOS 后台传输使用 NSURLSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33852545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com