本文转载至 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. JAVA常见算法题(十八)

    package com.xiaowu.demo; /** * 两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人,以抽签决定比赛名单. 有人向队员打听比赛的名单:a说他不和x比 ...

  2. CvArr、Mat、CvMat、IplImage、BYTE转换

    一.Mat类型:矩阵类型,Matrix.     在openCV中.Mat是一个多维的密集数据数组. 能够用来处理向量和矩阵.图像.直方图等等常见的多维数据.     Mat有3个重要的方法:     ...

  3. 【共享单车】—— React后台管理系统开发手记:AntD Form基础组件

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  4. cordova与ios native code交互的原理

    非常早曾经写了一篇博客,总结cordova插件怎么调用到原生代码:cordova调用过程,只是写得太水.基本没有提到原理.近期加深了一点理解,又一次补充说明一下 js调用native 以下是我们产品中 ...

  5. 【Excle数据透视表】如何将价格小于5000的显示为红色“不达标”

    例如下图:需要将价格小于5000的设置为低价格 步骤 单击"价格"列任意单元格→右键→数字格式→自定义→在类型下的文本框写入:[>=5000]G/通用格式;[红色][< ...

  6. 基于Android Classic Bluetooth的蓝牙聊天软件

    代码地址如下:http://www.demodashi.com/demo/12133.html BluetoothChat 基于Android Classic Bluetooth的蓝牙聊天软件,目前仅 ...

  7. mongoDB 索引的用法

    http://www.cnblogs.com/lipan/archive/2011/03/28/1997202.html MongoDB中的索引其实类似于关系型数据库,都是为了提高查询和排序的效率的, ...

  8. IBM Rational AppScan使用详细说明

    转自:http://www.nxadmin.com/tools/675.html 本文将详细介绍Appscan功能选项设置的细节,适合E文一般,初次接触Appscan的童鞋参考阅读. Appscan是 ...

  9. H5 打开App

    IOS 1.只能在safari浏览器打开, 2.必须App安装的情况下. 3.IOS必须配置 URLSchemes 为 "yidiandai://"  才可以. <!DOCT ...

  10. Ubuntu 16.04主题美化和软件推荐

    http://www.linuxidc.com/Linux/2016-09/135165.htm http://www.techweb.com.cn/network/system/2015-11-20 ...