UIDocumentInteractionController

UIDocumentInteractionController

本文介绍了通过UIDocumentInteractionController打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIDocumentInteractionController在我的应用程序中打开文档.我使用以下方法预览PDF文件:-

I am using UIDocumentInteractionController for opening documents in my app. I have used method below for previewing the PDF file:-

- (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从其他应用程序读取应用程序中的文件.

I have read that we can read files in an app from other app too by UIDocumentInteractionController.

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

In my app, How can I read the files from other app using UIDocumentInteractionController? How does all this happens?

推荐答案

预览PDF文档并共享.

Previewing the PDF document and sharing.

设置代表方法:-UIDocumentInteractionControllerDelegate

Set Delegate Method:-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

If you have any confusion, click on the below link and read :https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/PreviewingandOpeningItems.html

这篇关于通过UIDocumentInteractionController打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:45