我在应用中显示pdf文件。我想在唠叨栏上显示“打开方式”选项,显示安装在iPhone上的应用程序可以打开相同的pdf,如果用户选择任何应用程序(例如pdf查看器),那么pdf应该打开pdf viewer app。
我该怎么做?
请帮忙
提前致谢。
答案 0 :(得分:3)
要在设备上的可用应用程序中打开文件,请使用UIDocumentInteractionController类。
文档交互控制器与委托对象一起提供应用程序内支持,以管理用户与本地系统中文件的交互。例如,电子邮件程序可能使用此类来允许用户预览附件并在其他应用程序中打开它们。使用此类可以显示用于预览,打开,复制或打印指定文件的相应用户界面。
如果你遇到问题,那么就会有一些很多的问题。 search results for UIDocumentInteractionController
答案 1 :(得分:3)
此代码将显示您正在寻找的OpenIn交互。它适用于iPhone和iPad。在iPad上它是一个popover。我正在生成PDF,但是如果你只是使用了一个,则不需要编写文件,只需提交文件路径即可。
// 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];
}
答案 2 :(得分:1)
您可以使用“UIDocumentInteractionController”的Apple Default api进行检查。
以下是网址:
希望,它会解决您的问题。
干杯。