通过UIDocumentInteractionController打开文件

Tan*_*ain 4 ios uidocumentinteraction

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];

}
Run Code Online (Sandbox Code Playgroud)

我已经读过,我们也可以通过其他应用程序读取应用程序中的文件UIDocumentInteractionController.

在我的应用程序中,如何使用其他应用程序读取文件UIDocumentInteractionController?这一切是如何发生的?

Ani*_*mar 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;
}
Run Code Online (Sandbox Code Playgroud)

如果您有任何疑惑,请单击以下链接并阅读:https: //developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/PreviewingandOpeningItems.html