UIDocumentInteractionController:使用本机应用程序打开文件

时间:2013-04-04 10:21:47

标签: iphone ios

文档说UIDocumentInteractionController允许使用已安装的应用程序隐式打开文件(UTI属性为nil),但不是本机的。

UIDocumentInteractionController *controller = [UIDocumentInteractionController  interactionControllerWithURL:fileURL];
[controller retain];
controller.delegate = self;
//controller.UTI = uti;

CDVViewController* cont = (CDVViewController*)[ super viewController ];
CGRect rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height);
[controller presentOpenInMenuFromRect:rect inView:cont.view animated:YES];

是否可以在Safari中打开pdf文件或在图库中打开图像?

P.S。我是目标C的新人:)

2 个答案:

答案 0 :(得分:3)

无法说明设备必须打开文件的应用程序。

你可以使用 UIApplication's OpenUrl method以电话为例,或者使用某个网址启动Safari。 例如:

[[UIApplication sharedApplication] openURL:@"tel://%i", someNumber];

但是如果要打开特定文件,则必须使用UIDocumentInteractionController

还有QLPreviewController API来预览文档。 Here 是教程如何使用它并查看它的外观。

答案 1 :(得分:1)

我已使用presentPreviewAnimated预览文件UIDocumentInteractionController而不是presentOpenInMenuFromRect