iOS背景传输 – com.apple.nsurlsessiond文件夹中的tmp文件

我们编写了一个媒体应用程序,可以让您使用BACKGROUND FETCH获取最新视频列表作为json列表

那么它使用BACKGROUND TRANSFER来告诉iOS一个接一个地下载视频,然后回到睡眠状态,并在完成后唤醒应用程序.

它做到这一切,但我们注意到空间使用正在增长和增长.

我们添加了代码来清除所有下载的视频,但空间使用情况在设置中保持不变.

我们使用Xcode>下载了应用文件夹组织者>设备,并发现BACKGROUND TRANSFER tmp文件夹是tmp文件的沉闷.

这些不应该被清除

这通常是我使用的代码.
我认为主要是我附加多个DownloadTask(最多可以有30个)到一个后台会话.文件大小从电影到pdf文件不同.

NSURLSession * backgroundSession_ = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier];


backgroundSession_ = [NSURLSession sessionWithConfiguration:urlSessionConfigurationBACKGROUND_
                                                   delegate:self
                                              delegateQueue:[NSOperationQueue mainQueue]];

NSOperationQueue *mainQueue_ = [NSOperationQueue mainQueue];



NSURLSessionDownloadTask * downloadTask_ = [backgroundSession_ downloadTaskWithURL:url_];

downloadStarted_ = TRUE;
[downloadTask_ resume];

解决方法

从didFinishDownloadingToURL返回之前尝试这样的事情:
// App's Documents directory path
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)firstObject];

// Creating the path for the downloaded file
docsPath = [docsPath stringByAppendingPathComponent:downloadTask.response.suggestedFilename];

// Moving the file from temp location to App's Documents directory
[[NSFileManager defaultManager] moveItemAtPath:location.path toPath:docsPath error:NULL];

documentation表示您应该“从该委托方法返回之前将文件移动到应用程序的沙盒容器目录中的永久位置”(或许是Documents目录).

从doFinishDownloadingToURL(或下载失败)返回后,清除的临时文件 – 由操作系统自行决定(通常为内存压力).

以上是来客网为你收集整理的iOS背景传输 – com.apple.nsurlsessiond文件夹中的tmp文件全部内容,希望文章能够帮你解决iOS背景传输 – com.apple.nsurlsessiond文件夹中的tmp文件所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。