是否可以使用 Quick Look Framework 从 URL link 查看 PDF 文件
Is it possible to view a PDF file from an URL link using Quick Look Framework
如标题所述,我需要显示存储在远程服务器中的 PDF 文件,而无需仅使用 URL link 在设备上下载它。是否可以使用 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.
我已经通过 UIDocumentInteractionController
解决了
UIDocumentInteractionController *viewer = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
viewer.delegate = self;
[viewer presentPreviewAnimated:YES];
不,当前 QLFramework 不支持它。
所有 quicklook 支持的项目都应符合 "QLPreviewItem" 协议。
根据 QL 的文档
The methods in the QLPreviewItem protocol are also declared as a category on the NSURL class. As a result, you can use NSURL objects directly as preview items—provided that you want to use the default titles of those items.
QLPreviewItem 协议包含 previewItemURL 属性,它是 URL 类型。但是文档直接告诉我们:
The value of this property must be a file-type URL.
换句话说,它不接受其他 url 架构。
如标题所述,我需要显示存储在远程服务器中的 PDF 文件,而无需仅使用 URL link 在设备上下载它。是否可以使用 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.
我已经通过 UIDocumentInteractionController
UIDocumentInteractionController *viewer = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
viewer.delegate = self;
[viewer presentPreviewAnimated:YES];
不,当前 QLFramework 不支持它。 所有 quicklook 支持的项目都应符合 "QLPreviewItem" 协议。 根据 QL 的文档
The methods in the QLPreviewItem protocol are also declared as a category on the NSURL class. As a result, you can use NSURL objects directly as preview items—provided that you want to use the default titles of those items.
QLPreviewItem 协议包含 previewItemURL 属性,它是 URL 类型。但是文档直接告诉我们:
The value of this property must be a file-type URL.
换句话说,它不接受其他 url 架构。