UIDocumentPickerViewController和UIDocumentInteractionController

UIDocumentPickerViewController

补充一下,UIDocumentPickerModeOpen有点像readonly的模式,可以获取到NSURL,但是NSData无法通过NSURL获取真实的数据,建议优先使用UIDocumentPickerModeImport

重点要了解UIDocumentPickerViewController在初始化的时候inMode的四种模式:

  1. UIDocumentPickerModeImport: Import从提供者那里获得文件并拷贝到我们的host app。最经典的应用场景是在内容创建类应用中的使用。例如,像keynote、PowerPoint这样的演示制作应用,希望导入图片,视频,以及音频。它们希望拷贝一份这些数据以此保证它们随时可用。
  2. UIDocumentPickerModeOpen: 和import一样,open同样从文件提供者那里获得数据并导入我们的host app,只是不同的是,这些数据没有被拷贝一份至我们的host app,数据还在原处。例如,你或许在音乐播放器、视频播放器,再或者图像编辑器中使用该方式。
  3. UIDocumentPickerModeExportToService: Export使我们的host app可以保存文件至其它提供者。例如,这些提供者可能是常用的像Dropbox、iCloud Drive这样的云存储系统。host app可以通过export保存文件到提供者的存储空间。在接下来的编辑器例子中,当用户完成编辑,他们可以导出文件,然后稍后可以在其它app中打开这些文件。
  4. UIDocumentPickerModeMoveToService: 除了host app不会持有一份儿文件的拷贝,其它Moving和export差不多。这或许是最不常用的操作,因为大多数iOS apps不是为了抛弃它们的数据才创建的。

UIDocumentInteractionController

这个类相对简单一点,重点是要实现在delegate里面的3个方法, 这样视图控制器才能显示出来:

#pragma mark - UIDocumentInteractionControllerDelegate
-(UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
return self;
}
-(UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{
return self.view;
}
-(CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller{
return self.view.bounds;
}

UTI

苹果支持的文件类型使用UTI标识

Apple 文档:https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

在info.plist上配置app里面支持读取查看支持的文件类型

<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>com.myApp.surpportFiles</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image</string>
<string>public.audio</string>
<string>public.movie</string>
<string>public.data</string>
<string>public.text</string>
<string>public.archive</string>
<string>public.item</string>
<string>public.source-code</string>
</array>
</dict>
</array>

UIDocumentPickerViewController和UIDocumentInteractionController的更多相关文章

  1. 【iOS功能实现】之利用UIDocumentInteractionController打开和预览文档

    iOS提供了使用其他app预览文件的支持,这就是Document Interaction Controller.此外,iOS也支持文件关联,允许其他程序调用你的app打开某种文件.而且,从4.2开始, ...

  2. 下载文件 ,调用系统的方法(UIDocumentInteractionController) 查看

  3. UIDocumentInteractionController 文件预览

    //创建并从底部弹出来 - (void)viewDidLoad { [super viewDidLoad]; [self setupDocumentControllerWithURL:fileURL] ...

  4. ios开发之--UIDocumentInteractionController的使用(实现更多分享服务)

    最近在做项目的时候,碰到这样一个需求,就是本地生成pdf文件,然后本地打开,经过测试发现,pdf文件是无法保存到相册里面的,只能存到手机里面,鉴于苹果的存储机制,需要取出来,进行本地展示,可以直接传到 ...

  5. iOS利用UIDocumentInteractionController和Quick Look打开或预览文档

    在App的开发过程中,我们避免不了要打开软件中的文件,例如:Excel文件,Word文件,图片文件等不同格式的文件或者想要通过第三方的App来打开这些文件,那么我们就要用到UIDocumentInte ...

  6. Xcode 7.0 SDK(Software Development Kit) 及 Sandbox(沙盒) 存放路径

    1. Sandbox(沙盒) 存放路径 我的硬盘/Users/wj121/Library/Developer/CoreSimulator/Devices/879D7E35-BE50-4620-97E1 ...

  7. [New learn] UIKit 框架类

    NSObject NSObject is the root class of most Objective-C class hierarchies. NSDataAsset The NSDataAss ...

  8. iOS-关于使用其他应用打开本应用文档

    简介:本片文章是对官方文档的翻译,非常的感谢文章的翻译者:颐和园 官方地址:Document Interaction Programming Topics for iOS 文章的介绍内容: ***** ...

  9. 【Swift 2.1】共享文件操作小结(iOS 8 +)

    前言 适用于 iOS 8 + 本地共享文件列表 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs ...

随机推荐

  1. 2019-08-05 纪中NOIP模拟B组

    T1 [JZOJ1432] 输油管道 题目描述 请你帮忙设计一个从城市M到城市Z的输油管道,现在已经把整个区域划分为R行C列,每个单元格可能是空的也可能是以下7种基本管道之一: 油从城市M流向Z,‘+ ...

  2. AcWing 802. 区间和 离散化

    https://www.acwing.com/problem/content/804/ #include <iostream> #include <vector> #inclu ...

  3. [Note]后缀数组

    后缀数组 代码 void rsort() { for (int i = 1; i <= m; ++i) tax[i] = 0; for (int i = 1; i <= n; ++i) + ...

  4. 【转载】C/C++内存管理详解

    转自:http://chenqx.github.io/2014/09/25/Cpp-Memory-Management/ 内存管理是C++最令人切齿痛恨的问题,也是C++最有争议的问题,C++高手从中 ...

  5. CefApp和CefClient的作用

    CefApp 在cefsimple中,提到了一个cefapp的类型,这个类型是一个接口类,主要目的是提供获取三种handler的接口 /// // Implement this interface t ...

  6. mpvue 小程序 使用wx.request请求数据

    1.创建src下创建utils/wx-request.js const host = 'http://10.0.0.6:8081' function request (url, method, dat ...

  7. Euler Sums系列(五)

    \[\Large\displaystyle \sum_{n=1}^{\infty} \frac{\widetilde{H_n}}{n^{3}}\] where \(\widetilde{H_n}\) ...

  8. 【 SSH 整合】Spring、Struts、Hibernate基本整合

    applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...

  9. MySQL 学习(三)事务学习

    事务隔离级别     SQL标准的事务隔离级别包括:读未提交(read uncommitted).读提交(read committed).可重复读(repeatable read)和串行化(seria ...

  10. find 报错 find: paths must precede expression:

    编写shell脚本,报错,如下面 [root@localhost backup]#find ./ -name mysqldump* -mtime +3 -delete [root@localhost ...