我有NSURLSessionDownloadTask
一个backgroundSessionConfigurationWithIdentifier
。当我锁定屏幕时,会发生此异常:
错误域 = NSPOSIXErrorDomain 代码 = 1 “操作无法完成 操作不允许。”。
此错误仅出现在我的手机上,不会出现在其他手机上。
下面是简单的代码:
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.edu.downLoadTest"];;
AFURLSessionManager *_session = [[AFURLSessionManager alloc] initWithSessionConfiguration:sessionConfiguration];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://podcasts.apple.com/apple_keynotes_hd/2015/2015_mar_hd_cc.m4v"]];
NSProgress *progress;
NSURLSessionDownloadTask *task1 = [_session downloadTaskWithRequest:request progress:&progress destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSString *a =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
return [NSURL fileURLWithPath:[a stringByAppendingPathComponent:@"test.m4v"]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"%@",error);
}];
[task1 resume];