Opening a file by UIDocumentInteractionController

隐身守侯 提交于 2019-11-30 17:23:26

问题


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

}

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

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


回答1:


Previewing the PDF document and sharing.

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

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



来源:https://stackoverflow.com/questions/25787248/opening-a-file-by-uidocumentinteractioncontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!