objective C QLPreviewController does not display image

梦想与她 提交于 2019-12-11 18:13:27

问题


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

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:

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

来源:https://stackoverflow.com/questions/47475957/objective-c-qlpreviewcontroller-does-not-display-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!