UIDocumentInteractionController 第三方应用中打开自己的文件 方法

来源:互联网 发布:python 输入ctrl c 编辑:程序博客网 时间:2024/05/01 14:00
听起来好复杂,其实很简单,在你的.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 ,而且,最好做个判断,当读取的可用软件为空时,给用户一个提示,要不然用户会丈二和尚的⋯⋯

0 0
原创粉丝点击