与其他应用程序打开PDF

我正在一个应用程序中显示一个PDF文件。 我想显示“打开”选项上显示的应用程序安装在iPhone上,可以打开相同的PDF,如果用户select任何应用程序(例如PDF查看器),那么PDF应该打开PDF查看器应用程序。

我该怎么做呢?

请帮忙

提前致谢。

此代码将呈现您正在寻找的OpenIn交互。 它适用于iPhone和iPad。 在iPad上,它在stream行。 我生成的PDF,但如果你只是使用一个你不需要writeToFile,只需交给filePath。

// In your header. MyViewController.h @interface MyViewController : UIViewController <UIDocumentInteractionControllerDelegate> { UIDocumentInteractionController *docController; } // In your implementation. MyViewController.m Open Results is hooked up to a button. - (void)openResults { // Generate PDF Data. NSData *pdfData = [self makePDF]; // Create a filePath for the pdf. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Report.pdf"]; // Save the PDF. UIDocumentInteractionController has to use a physical PDF, not just the data. [pdfData writeToFile:filePath atomically:YES]; // Open the controller. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]]; docController.delegate = self; docController.UTI = @"com.adobe.pdf"; [docController presentOpenInMenuFromBarButtonItem:shareButton animated:YES]; } 

要在设备上的可用应用程序中打开文件,请使用UIDocumentInteractionController类。

文档交互控制器以及委托对象提供了应用程序内支持,用于pipe理用户与本地系统中文件的交互。 例如,电子邮件程序可能会使用此类来允许用户预览附件并在其他应用程序中打开它们。 使用此类来呈现用于预览,打开,复制或打印指定文件的适当用户界面。

如果你遇到困难,围绕它有很多问题。 UIDocumentInteractionController的search结果

你可以检查“UIDocumentInteractionController”苹果默认的API。

以下是url:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html

希望它能解决你的问题。

干杯。