2014-09-11 103 views
1

我使用UIDocumentInteractionController在我的應用程序中打開文檔。我用下面的方法進行預覽PDF文件: -UIDocumentInteractionController打開文件

- (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從其他應用程序讀取文件?這一切是如何發生的?

回答

2

預覽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

相關問題