I am trying to upload a file using AFNetworking (2.5.4). The download is completed, the completion handler is called, with the error set to nil, everything looks fine, but the target file does not exist:
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];
The file path is the usual path available for my application:
/var/mobile/Containers/Data/Application/APP-GUID-REDACTED/Documents/FILE-NAME-REDACTED.docx
I used a different method before AFNetworking, and it could write to the same path just fine. The headers of the HTTP responses show everything perfectly (status 200, the correct length of the content, etc.), and if I twist the download URL, it downloads the file without any problems. No problem with the file.
Why is my destination file not written in the completion handler, despite the absence of errors?
UPDATE: I also tried AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; but nothing changes. I also tried to create an NSProgress pointer and send it for the progress argument, but to no avail.
ios ios8 afnetworking-2
Can poyrazoğlu
source share