gpt4 book ai didi

ios - NSURLSessionDownloadTask 继续下载,即使我杀死了应用程序

转载 作者:行者123 更新时间:2023-11-29 11:28:52 24 4
gpt4 key购买 nike

我正在使用 NSURLSessionDownloadTask 下载网页文件。当我使用 [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:] 创建 NSURLSessionConfiguration 时,我发现 NSURLSessionDownloadTask 继续下载,即使我终止了应用程序。这不是我所期望的,我只是希望它在后台下载。我不想终止该应用程序,它仍在下载中。

NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"DDDownloader"];
config.timeoutIntervalForRequest = 10;
self.session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];

NSURLSessionDownloadTask *downloadTask = [self.session downloadTaskWithURL:[NSURL URLWithString:downloadModel.url]];
[downloadTask resume];

希望我杀掉app后,app不再执行下载任务。

最佳答案

我现在已经有了大概的想法。我在苹果文档中看到了[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:]的描述:

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 to 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.

因为我在 xcode 上使用关闭按钮来关闭和重新启动我的应用程序,这就是苹果文档所说的:“iOS 应用程序被系统终止并重新启动。”当应用以这种方式关闭时,NSURLSessionDownloadTask 不会结束。如果用户从多任务屏幕关闭应用程序,系统将取消所有 session 的后台传输。

那么我的问题就解决了!

关于ios - NSURLSessionDownloadTask 继续下载,即使我杀死了应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55684086/

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