当我通过按电源按钮强制我的设备进入睡眠模式时,我的后台任务通过调用委托方法停止didCompleteWithError
并出现错误:
操作无法完成。不允许操作
如何配置我的 NSURLSession 以在睡眠模式下继续下载?
甚至可能吗?如果没有,我有什么选择?我需要下载一个 300Mb 的文件,因此在连接低的情况下,应用程序将在下载结束前进入睡眠模式。
这是我的会话的创建:
static NSURLSession *backgroundSession;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
backgroundSession = [NSURLSession sessionWithConfiguration:
[NSURLSessionConfiguration backgroundSessionConfiguration:
@"com.myapp.mytask"] delegate:self.
myDelegate delegateQueue:self.myQueue];
});
NSURLSessionDownloadTask *task = [backgroundSession downloadTaskWithRequest:
self.urlRequest];
[task resume];