bri*_*ear 13 ios background-fetch
我们编写了一个媒体应用程序,允许您使用BACKGROUND FETCH获取最新视频列表作为json列表
然后它使用BACKGROUND TRANSFER告诉iOS逐个下载视频并返回睡眠状态并在应用完成后唤醒应用程序.
它完成了所有这些,但我们注意到空间使用正在增长和增长.
我们添加了代码来清除所有下载的视频,但空间使用情况在设置中保持高
我们使用Xcode> Organizer> Devices下载了app文件夹,发现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];
Run Code Online (Sandbox Code Playgroud)

在返回之前尝试这样的事情didFinishDownloadingToURL:
// App\'s Documents directory path\nNSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];\n\n// Creating the path for the downloaded file\ndocsPath = [docsPath stringByAppendingPathComponent:downloadTask.response.suggestedFilename];\n\n// Moving the file from temp location to App\'s Documents directory\n[[NSFileManager defaultManager] moveItemAtPath:location.path toPath:docsPath error:NULL];\nRun Code Online (Sandbox Code Playgroud)\n\n该文档指出,您应该“在从此委托方法返回之前将文件移动到 app\xe2\x80\x99s 沙箱容器目录中的永久位置”(可能是Documents目录)。
\n\n返回后didFinishDownloadingToURL(或者下载失败),临时文件将被清除 - 由操作系统自行决定(通常在内存压力下)。
| 归档时间: |
|
| 查看次数: |
1317 次 |
| 最近记录: |