【问题标题】:Is it possible to view a PDF file from an URL link using Quick Look Framework是否可以使用 Quick Look Framework 从 URL 链接查看 PDF 文件
【发布时间】:2016-01-21 17:17:00
【问题描述】:

正如标题所说,我需要显示存储在远程服务器中的 PDF 文件,而无需使用 URL 链接将其下载到设备上。使用Quick Look框架可以做到吗?

我在下面使用这个代码:

- (void)openDocument {
    QLPreviewController *docPreviewController = [[QLPreviewController alloc] init];
    [docPreviewController setDataSource:self];
    [docPreviewController setDelegate:self];
    [docPreviewController setCurrentPreviewItemIndex:sender.tag];
    [self.destinationViewController presentViewController:docPreviewController animated:true completion:nil];
}

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

- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
    return [NSURL fileURLWithPath:@"http://www.domain.com/file.pdf"];
}

但我在控制台中遇到了这个问题:

UIDocumentInteractionController: invalid scheme https.  Only the file scheme is supported.

【问题讨论】:

标签: ios objective-c xcode quicklook


【解决方案1】:

不,当前的 QLFramework 不支持。 所有 quicklook 支持的项目都应该符合“QLPreviewItem”协议。 根据QL的文档

QLPreviewItem 协议中的方法也被声明为 NSURL 类上的一个类别。因此,您可以直接使用 NSURL 对象作为预览项目——前提是您希望使用这些项目的默认标题。

QLPreviewItem 协议包含previewItemURL 属性,它是一个URL 类型。但是文档直接告诉我们:

此属性的值必须是文件类型的 URL。

换句话说,它不接受其他 url 架构。

【讨论】:

    【解决方案2】:

    我已经通过UIDocumentInteractionController解决了

    UIDocumentInteractionController *viewer = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
    viewer.delegate = self;
    [viewer presentPreviewAnimated:YES];
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 2015-09-12
      • 2010-09-12
      • 2013-06-16
      • 1970-01-01
      • 2013-02-08
      • 1970-01-01
      • 2012-08-08
      • 2015-12-24
      相关资源
      最近更新 更多