Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AFNetworking downloadTaskWithRequest:progress:destination:completionHandler:未将文件写入路径_Ios_Ios8_Afnetworking 2 - Fatal编程技术网

Ios AFNetworking downloadTaskWithRequest:progress:destination:completionHandler:未将文件写入路径

Ios AFNetworking downloadTaskWithRequest:progress:destination:completionHandler:未将文件写入路径,ios,ios8,afnetworking-2,Ios,Ios8,Afnetworking 2,我正在尝试使用AFNetworking(2.5.4)下载一个文件。下载完成,调用完成处理程序,错误设置为nil,一切正常,但目标文件不存在: AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; NSString *fullPath = [valid path from my apps local manager] NSURLSessionDownloadTask *downloadTask = [manager down

我正在尝试使用AFNetworking(2.5.4)下载一个文件。下载完成,调用完成处理程序,错误设置为nil,一切正常,但目标文件不存在:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSString *fullPath = [valid path from my apps local manager]
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:req progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    return [NSURL URLWithString:fullPath];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
    NSLog(@"Saved file to %@.", filePath);
    *** [[NSFileManager defaultManager] fileExistsAtPath:filePath.absoluteString] returns NO here ***
}];
[cell.progressView setProgressWithDownloadProgressOfTask:downloadTask animated:YES];
[downloadTask resume];
文件路径是我的应用程序具有写入权限的常规路径:

/var/mobile/Containers/Data/Application/APP-GUID-redact/Documents/FILE-NAME-redact.docx

我在使用AFNetworking之前使用了一种不同的方法,它可以写入完全相同的路径。HTTP响应头完美地显示了所有内容(状态200、正确的内容长度等),如果我卷曲下载URL,它将下载文件而不会出现任何问题。这个文件没有问题

为什么我的目标文件没有在完成处理程序中写入,尽管没有错误


更新:我还尝试了
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]但它不会改变任何东西。我还尝试创建一个
NSProgress
指针,并将其发送给
progress
参数,但没有效果。

这里的问题是错误的文件路径或无效的文件路径。我也有同样的问题

创建如下所示的路径:

NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *filePathURL = [documentsDirectoryURL URLByAppendingPathComponent:[NSString stringWithFormat:@"your file name here",i]];
现在使用上面的路径:

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:req progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    return filePathURL;
}

使用[NSURL fileURLWithPath:(而不是URLWithString)


复制粘贴,没有更改。您的代码生成的路径与我的路径完全相同,并且再次为零。
return [NSURL fileURLWithPath:fullPath];