您的位置:首页 > 产品设计 > UI/UE

UIDocumentInteractionController 的使用

2015-09-11 15:35 519 查看
听起来好复杂,其实很简单,在你的.h文件中添加UIDocumentInteractionControllerDelegate

然后在.m文件中,新建一个方法,用来响应你点击按钮弹出时弹出popView,其中会罗列可打开当前文件的其他应用

我的方法如下

-(void)openDocumentIn{

documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:unEncodingURL]];

documentController.delegate = self;
documentController.UTI = @"com.microsoft.word.doc";

[documentController presentOpenInMenuFromRect:CGRectMake(760, 20, 100, 100) inView:self.view animated:YES];

}
其中的 documentController.UTI 表示那些类型的文件支持第三方软件打开,此链接里面有各种类型文件对应的参数https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html 可用根据unEncodingURl中的文件后缀名去动态设置这个值

rect 根据自己的需求写

然后delegate里面的方法自己看看应该能明白是什么意思

就不多说了

PS:此法必须使用真机来测试,而且真机测试前最好先下载几个可以支持你所需文件的软件,比如我就安装了WPSOFFICE ,而且,最好做个判断,当读取的可用软件为空时,给用户一个提示,要不然用户会丈二和尚的⋯⋯
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: