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 ,而且,最好做个判断,当读取的可用软件为空时,给用户一个提示,要不然用户会丈二和尚的⋯⋯
然后在.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 ,而且,最好做个判断,当读取的可用软件为空时,给用户一个提示,要不然用户会丈二和尚的⋯⋯
相关文章推荐
- UIday1402:mac 终端 常用命令
- HDU 5136 Yue Fei's Battle
- 关于UICollectionViewController
- UIScrollView及UIPageControl的使用
- getgid getuid
- UGUI 按钮的监听事件系统
- UITableViewCell的4种显示格式
- UITableViewCell的4种显示格式
- Jsp中引用的taglib标签的声明和${pageContext.request.contextPath} 的含义
- UGUI 5.0版本Anchors功能详解
- easy ui 表单ajax和from两种提交数据方法
- 一种让 IE6/7/8 支持 media query 响应式设计的方法
- DataGuard Gap sequence的处理方法
- getContextPath、getServletPath、getRequestURI的区别
- parquet原理分析
- 探究requestDisallowInterceptTouchEvent失效的原因
- 简析StringBuffer与StringBuilder
- LeetCode_Implement Stack using Queues
- 页面顺序载入UI 方法
- Long Term Time Series Prediction and Stock Value Prediction