我正在使用UIDocumentInteractionController
在我的应用中打开文档。我使用下面的方法预览PDF文件: -
- (IBAction)previewDocument:(id)sender
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"pdf"];
// Initialize Document Interaction Controller
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
// Configure Document Interaction Controller
[self.documentInteractionController setDelegate:self];
// Preview PDF
[self.documentInteractionController presentOptionsMenuFromRect:down.frame inView:self.view animated:YES];
}
我已经读过,我们可以通过UIDocumentInteractionController
从其他应用中读取应用中的文件。
在我的应用中,如何使用UIDocumentInteractionController
从其他应用中读取文件?这一切是如何发生的?
答案 0 :(得分:5)
预览PDF文档并进行共享。
设置委托方法: - UIDocumentInteractionControllerDelegate
NSURL *URL = [[NSBundle mainBundle] URLForResource:@"Your PDF Name" withExtension:@"pdf"];
UIDocumentInteractionController *documentInteractionController =[UIDocumentInteractionController interactionControllerWithURL:URL];
documentInteractionController.delegate = self;
[documentInteractionController presentPreviewAnimated:YES];
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
return self;
}
如果您有任何疑惑,请点击以下链接阅读: https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/PreviewingandOpeningItems.html