0
votes

i used Afnetworking to download image file, and display it using QlViewController. Here is my image: enter image description here

Here is my code to download and display image:

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"NSProgress: %@", uploadProgress);
//        [SVProgressHUD showProgress:uploadProgress.fractionCompleted];
    } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
        NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
        return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
    } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
        [SVProgressHUD dismiss];
        if(!error){
            filePartToView = filePath;
            QLPreviewController *previewController=[[QLPreviewController alloc]init];
            previewController.delegate=self;
            previewController.dataSource=self;
            [self.navigationController presentViewController:previewController animated:YES completion:nil];
            [previewController.navigationItem setRightBarButtonItem:nil];
        }else{
            [Utilities showAlertDialog:[NSString stringWithFormat:@"Download file fail: \%@", [error localizedDescription]] atViewController:self];
        }
    }];
    [downloadTask resume];

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}

- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return filePartToView;
}

When debug this line:

filePartToView = filePath;

I got:

po filePath
file:///Users/macos/Library/Developer/CoreSimulator/Devices/90966F81-A0D1-4CCF-BA9B-B306AAB62993/data/Containers/Data/Application/676B50E3-E364-4CDB-85DC-BF90D4C8FAED/Documents/IMG_0002.JPG

But when present in QLPreviewController:

enter image description here

I dont know why it happened, can anyone help my problem?

can some one help?kemdo
Have you checked that you have a valid image at that path? 1 KB seems small for a JPEG image. Any logs in Console?Thomas Deniau
hello. I checked NSLog(@"NSProgress: %@", uploadProgress); then see uploadProgress downloaded full my image size ~2.4M. But when convert asset to NSData i see it very short, dont know whykemdo
i am think that the issue come from package wrong when download. Or may be it fail when save to pathkemdo
In case of loading smaller image size, it's okkemdo