app 之间发送文件 ios
本文转载至 http://www.51094.com/?p=212
第一种: 发送一个正常的 pdf 文件,只要是能读取pdf 的都能得到响应
-(IBAction)openDocumentIn:(id)sender {
NSString * filePath = [[NSBundle mainBundle] pathForResource:@"ASIHttpRequest" ofType:@"pdf"];
UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
documentController.delegate = self;
[documentController retain];
documentController.UTI = @"com.ddsfsd.TestForDocument.pdf";//com.ddsfsd.TestForDocument.pdf 可以为随意字符 目前没发现用处
//一下三选一
// [documentController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
// [documentController presentPreviewAnimated:YES];
[documentController presentOptionsMenuFromBarButtonItem:barBtnItem animated:YES];
}
- (UIViewcontroller*)documentInteractionControllerViewcontrollerForPreview:(UIDocumentInteractionController*)controller
{
return self;
}
- (UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller
{
return self.view.frame;
}
// 点击预览窗口的“Done”(完成)按钮时调用
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController*)_controller
{
[_controller autorelease];
}
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>文档类型名称
<string>pdf</string>
<key>LSHandlerRank</key> //是拥有此类型文档,还是仅用于打开
<string>Default</string>
</dict>
</array>
一般而言一个文档类型和一个文件类型对应,当然也可以是多个文件类型例如。doc/。docx是word文档在两个不同版本下的文件后缀。这样你可以把这两个文件类型组合在一个文档类型中
A uniform type identifier (UTI) is a string that identifies a class of entities with a type. UTIs are typically used to identify the format for files or in-memory data types and to identify the hierarchical layout of directories, volumes or packages
这里有个基本的对照表,文件后缀和UTI的串
https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html
* Item0类型为Dictionary
* CFBundleTypeName:文档类型名
* LSHandleRank:应用的所有者(以上声明的这种文件类型的创建者),有Alternate(这种文件类型的另外一个浏览者)、None或Default
* CFBundleTypeRole:应用通过什么方式处理这种文件:Editor、Viewer、Shell或None
* LSItemContentTpyes:Array类型,它包含表示这种文件类型的UTI数组
通过以上设置就可以向IOS注册你的应用,以便可以处理PDF文档。
当一个PDF文档传到应用中后,应用就会自动调用方法:application:openURL:sourceApplication:annotation: 该方法必须在application delegate中实现。
第二种:发送一个自定义后缀名的文件,对其他应用隐藏、 假定后缀为 pdf1 文件, 则发送的 uti 需要对应
-(IBAction)openDocumentIntwo:(id)sender {
NSString * filePath = [[NSBundle mainBundle] pathForResource:@"ASIHttpRequest" ofType:@"pdf1"];
UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
documentController.delegate = self;
[documentController retain];
documentController.UTI = @"com.ddsfsd.TestForDocument.pdf1";//com.ddsfsd.TestForDocument.pdf 可以为随意字符 目前没发现用处
//一下三选一
// [documentController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
// [documentController presentPreviewAnimated:YES];
[documentController presentOptionsMenuFromBarButtonItem:barBtnItem animated:YES];
}
- (UIViewcontroller*)documentInteractionControllerViewcontrollerForPreview:(UIDocumentInteractionController*)controller
{
return self;
}
- (UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller
{
return self.view.frame;
}
// 点击预览窗口的“Done”(完成)按钮时调用
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController*)_controller
{
[_controller autorelease];
}
接收方:设置
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>com.ddsfsd.TestForDocument.pdf1</string>//应用的唯一标识 com+bundle Identifier,
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>//文件扩展名
<string>pdf1</string> //使用pdf1
</dict>
</dict>
</array>
参考:
http://developer.apple.com/library/IOS/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1
http://stackoverflow.com/questions/4186401/how-do-i-register-a-custom-filetype-in-IOS
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>文档类型名称
<string>pdf</string>
<key>LSHandlerRank</key> //是拥有此类型文档,还是仅用于打开
<string>Default</string>
</dict>
</array>
完成以上配置,则再呼叫其他程序时,只能找到自己定义的应用,及实现自己的应用间相互传递文件,而屏蔽掉其他应用
app 之间发送文件 ios的更多相关文章
- iOS APP之间到跳转,以及热门应用,手机自带到应用跳转
应用之间的跳转 在第一个APP中,做如下操作:1.在info.plist文件中的"信息属性列表"下添加一项:"URL类型"; 2.点开"URL类型&q ...
- iOS App之间常用的五种通信方式及适用场景总结
iOS系统是相对封闭的系统,App各自在各自的沙盒(sandbox)中运行,每个App都只能读取iPhone上iOS系统为该应用程序程序创建的文件夹AppData下的内容,不能随意跨越自己的沙盒去访问 ...
- iOS日常学习 - App之间常用的五种通信方式及适用场景总结
本文为转载学习,原文地址 iOS系统是相对封闭的系统,App各自在各自的沙盒(sandbox)中运行,每个App都只能读取iPhone上iOS系统为该应用程序程序创建的文件夹AppData下的内容,不 ...
- iOS中两个APP之间的跳转和通信
app间的跳转 一:在第一个app首先要做下面这些操作: 1.在info.plist文件中的Information Property List下添加一项:URL types. 2.点开URL type ...
- python 全栈开发,Day129(玩具开机提示语,为多个玩具发送点播,聊天界面,app录音,app与服务器端文件传输,简单的对话)
一.玩具开机提示语 先下载github代码,下面的操作,都是基于这个版本来的! https://github.com/987334176/Intelligent_toy/archive/v1.2.zi ...
- 需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP
需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP 需求:过滤下面这个网页里共723行 校对中里 行数为两位数 ...
- ios两个app之间跳转,传值的实现
两个APP之间的跳转是通过[[UIApplication sharedApplication] openURL:url]这种方式来实现的. 1.首先设置第一个APP的url地址 2.接着设置第二个AP ...
- iOS App之间跳转
1.先来看看效果,这里做了三个功能 从MyApp跳转到YourApp 从MyApp跳转到YourApp的指定页面 从YourApp使用跳转url的方式跳回MyApp 2.实现app之间的跳转需要注意两 ...
- UWP开发:APP之间的数据交互(以微信为例)
目录 说明 UWP应用唤醒方式 跟微信APP交互数据 APP之间交互数据的前提 说明 我们经常看到,在手机上不需要退到桌面,APP之间就可以相互切换,并且可以传递数据.比如我在使用知乎APP的时候,需 ...
随机推荐
- 如何把自己的代码发布到npmjs(npm publish)
来源: https://www.cnblogs.com/calamus/p/8384318.html
- java中XML操作:xml与string互转、读取XML文档节点及对XML节点增删改查
一.XML和String互转: 使用dom4j程式变得很简单 //字符串转XML String xmlStr = \"......\"; Document document = D ...
- EM算法和GMM模型推导
- zabbix proxy分布式监控部署
一.proxy分布式监控介绍 来源于zabbix官网: https://www.zabbix.com/documentation/3.4/zh/manual/distributed_monitorin ...
- nodejs - 根据用户地址不同 返回不同数据
年前忙疯了 之前写连续上班12天的时候 感觉自己太天真了 年前连续上班20天 真心苦逼成狗 好几次晚上12点到家 然后 最近 也灭有学习太多 就是项目上的 事情 真心忙啊 简单写了一段 Nodej ...
- python sqlite3 MySQLdb
SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python就 ...
- mysql 杀掉(kill) lock进程脚本
杀掉lock进程最快的方法是重启mysql,像你这种情况,1000多sql锁住了,最好是重启如果不允许重启,我提供一个shell脚本,生成 kill id命令杀掉lock线程,如下:--------- ...
- Pycharm中的scrapy安装教程
在利用pycharm安装scrapy包是遇到了挺多的问题.在折腾了差不多折腾了两个小时之后总算是安装好了.期间各种谷歌和百度,发现所有的教程都是利用命令行窗口安装的.发现安装scrapy需要的包真是多 ...
- 怎样封装RESTful Web Service
所谓Web Service是一个平台独立的,低耦合的.自包括的.可编程的Web应用程序.有了Web Service异构系统之间就能够通过XML或JSON来交换数据,这样就能够用于开发分布式的互操作的应 ...
- springboot学习(二) 第一个springboot项目:Hello World!
1.简介 可以像使用其他java标准库那样使用spriongboot,只需简单地在你的classpath下包含正确的 spring-boot-*.jar 文件.springboot不需要集成任何特殊的 ...