UIDocumentInteractionController -iOS预览、打开文档(doc、pdf等)
来源:互联网 发布:网络游戏修改数据 编辑:程序博客网 时间:2024/05/17 04:57
UIDocumentInteractionController-iOS预览、打开文档(doc、pdf等)
最近公司一个项目有个需求,要求打印文档或者发送文档到QQ、邮箱等去打印
就这个需求在网上查看了一些相关的文档,发现还真有一个现成可用的类-UIDocumentInteractionController
,是iOS很早就出来的一个功能,这是一个被我们完全忽略掉的东西,真的是压根就没听说过,但是它却具有着强大的功能。
强大的文档阅读器,主要功能如下:
- 预览文档,包括word文档、excel文档、pdf文档等等
- 调用iPhone里第三方的app打开文档
- 将文档用系统级分享到各个应用中(包括QQ、微信、邮箱等)
- 如果有条件配备支持AirPrint的打印机的话,就可以直接打印文档
用法相当简单(用swift语言实现,OC基本一样):
1、初始化一个UIDocumentInteractionController对象
//测试用的文件Urllet docUrl = Bundle.main.url(forResource: "test1", withExtension: "pdf")//先初始化一个UIDocumentInteractionController对象(传入相应的文件url(本地和远程都可以))let documentController = UIDocumentInteractionController(url:docUrl!)
2、本应用内预览文档
//设置代理 --本应用内预览必须要添加代理UIDocumentInteractionControllerDelegatedocumentController.delegate = self;//当前APP打开 需实现协议方法才可以完成预览功能documentController.presentPreview(animated: true)//需要实现如下代理方法public func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController{ //这个地方需要返回给一个控制器用于展现documentController在其上面,所以我们就返回当前控制器self return self}
3、在其他应用中打开、分享
//第三方打开 手机中安装有可以打开此格式的软件都可以打开documentController.presentOpenInMenu(from: (sender as! UIButton).frame, in: self.view, animated: true)
over… 差不多就简单介绍到这里啦!
demo已上传到github:文档阅读器demo
1 0
- UIDocumentInteractionController -iOS预览、打开文档(doc、pdf等)
- iOS预览PDF文档 UIDocumentInteractionController
- UIDocumentInteractionController 预览和打开文档
- 【iOS功能实现】之利用UIDocumentInteractionController打开和预览文档
- iOS利用UIDocumentInteractionController和Quick Look打开或预览文档
- 之利用UIDocumentInteractionController打开和预览文档
- 预览 doc docx,xls,xlsx,pdf等API 说明文档
- 用UIWebView打开文档(doc、xls、pdf等)
- UIDocumentInteractionController的使用之打开和预览文档
- 预览和打开PDF文档
- 预览doc、xslx等Office文档和pdf以及Quicklook中QLPreviewController
- 利用UIDocumentInteractionController文档预览以及调用iPhone里第三方相关的app打开文档
- UIWebview打开doc,pdf 等文件
- iOS在app中打开word、execl、pdf等文档
- ios预览和打开文档
- 【iOS】预览和打开文档
- java实现txt、excle、pdf、doc文档的在线预览
- UIDocumentInteractionController 文档交互控制器 pdf 游览
- 设计模式复习笔记 (13)结构型模式:外观模式
- Android中Mvp模式的使用
- selenium webdriver(Appium)如何等待页面元素加载完成
- 在应用程序中,启动默认浏览器打开指定网站的解决办法
- 补10.5
- UIDocumentInteractionController -iOS预览、打开文档(doc、pdf等)
- win32画直线
- IM推送之客户端SDK开发(一)
- 使用系统提供的对话框来显示信息的办法(非MessageBox)
- 区块链有哪些
- 基于TestNG+Mockito及自动装配注解的Spring MVC集成测试
- Lua 之__index域
- 全球聚焦中国“双创周”,各路大佬和风投都来了
- 直角矩形的画法