本文转载至 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的更多相关文章

  1. iOS APP之间到跳转,以及热门应用,手机自带到应用跳转

    应用之间的跳转 在第一个APP中,做如下操作:1.在info.plist文件中的"信息属性列表"下添加一项:"URL类型"; 2.点开"URL类型&q ...

  2. iOS App之间常用的五种通信方式及适用场景总结

    iOS系统是相对封闭的系统,App各自在各自的沙盒(sandbox)中运行,每个App都只能读取iPhone上iOS系统为该应用程序程序创建的文件夹AppData下的内容,不能随意跨越自己的沙盒去访问 ...

  3. iOS日常学习 - App之间常用的五种通信方式及适用场景总结

    本文为转载学习,原文地址 iOS系统是相对封闭的系统,App各自在各自的沙盒(sandbox)中运行,每个App都只能读取iPhone上iOS系统为该应用程序程序创建的文件夹AppData下的内容,不 ...

  4. iOS中两个APP之间的跳转和通信

    app间的跳转 一:在第一个app首先要做下面这些操作: 1.在info.plist文件中的Information Property List下添加一项:URL types. 2.点开URL type ...

  5. python 全栈开发,Day129(玩具开机提示语,为多个玩具发送点播,聊天界面,app录音,app与服务器端文件传输,简单的对话)

    一.玩具开机提示语 先下载github代码,下面的操作,都是基于这个版本来的! https://github.com/987334176/Intelligent_toy/archive/v1.2.zi ...

  6. 需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP

    需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP 需求:过滤下面这个网页里共723行 校对中里 行数为两位数 ...

  7. ios两个app之间跳转,传值的实现

    两个APP之间的跳转是通过[[UIApplication sharedApplication] openURL:url]这种方式来实现的. 1.首先设置第一个APP的url地址 2.接着设置第二个AP ...

  8. iOS App之间跳转

    1.先来看看效果,这里做了三个功能 从MyApp跳转到YourApp 从MyApp跳转到YourApp的指定页面 从YourApp使用跳转url的方式跳回MyApp 2.实现app之间的跳转需要注意两 ...

  9. UWP开发:APP之间的数据交互(以微信为例)

    目录 说明 UWP应用唤醒方式 跟微信APP交互数据 APP之间交互数据的前提 说明 我们经常看到,在手机上不需要退到桌面,APP之间就可以相互切换,并且可以传递数据.比如我在使用知乎APP的时候,需 ...

随机推荐

  1. ISP模块之RAW DATA去噪(一)

    ISP(Image Signal Processor),图像信号处理器,主要用来对前端图像传感器输出信号处理的单元,主要用于手机,监控摄像头等设备上. RAW DATA,可以理解为:RAW图像就是CM ...

  2. SparkStreaming数据源Flume实际案例分享

    一.什么是Flume? flume 作为 cloudera 开发的实时日志收集系统,受到了业界的认可与广泛应用.Flume 初始的发行版本目前被统称为 Flume OG(original genera ...

  3. Spring声明式事务的配置方式

    1.事务的特性   原子性:事务中的操作是不可分割的一部分   一致性:要么同时成功,要么同时失败(事务执行前后数据保持一致)   隔离性:并发互不干扰     持久性:事务一旦被提交,它就是一条持久 ...

  4. C++ 设置文件最近修改时间

    利用VS开发C++项目,经常发现修改系统时间后,每次编译过程会变得很慢,其原因就是当你把系统时间调到未来的一个时间点,然后有意或者无意编辑过一些代码文件,那么这些文件的时间戳就停留在未来. 当你把系统 ...

  5. java web 分页实现

       分页实现的效果:    ///////// /////////////////////////////////////////////////////// /////////////////// ...

  6. react-native 路由 react-native-router-flux

    引言 react-native-router-flux 是一个基于 react-navigation 路由框架,进一步简化了页面跳转的步骤,并且一直随着 react-navigation升级更新版本. ...

  7. 1通过URL对象的openStream()方法能够得到指定资源的输入流。

    通过URL读取网页内容     1通过URL对象的openStream()方法能够得到指定资源的输入流.     2通过输入流能够读取.訪问网络上的数据.     案例: import java.io ...

  8. springMVC+json构建restful风格的服务

    首先.要知道什么是rest服务,什么是rest服务呢? REST(英文:Representational State Transfer,简称REST)描写叙述了一个架构样式的网络系统.比方 web 应 ...

  9. C#常见的概念阐述

    在上篇文章中,你跟着我写了一个HelloWorld,本篇中,我们来谈谈一些C#程序中的小概念 1.C# 程序结构 一个 C# 程序主要包括以下部分: 命名空间声明(Namespace declarat ...

  10. 对ListView滚动状态的监听

    有的时候,我们需要对ListView滚动做一个相应的监听事件,例如:要实现如下图通讯录的功能: 思路为:首先呢,中间那个"路"字为一个TextView,它与ListView采用相对 ...