本文转载至 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. 解决svn锁定

    问题:今天去公司 svn-update的时候,报错svn:E155004,提示说什么locked 解决:svn cleanup解除锁定,然后就可以操作了. 原因:SVN 本地更新时,由于一些操作中断更 ...

  2. 时间操作(JavaScript版)—最简单比較两个时间格式数据的大小

    呵呵呵,在软件研发过程中假设遇到要比較两个时间的大小.你会怎么做.嗯嗯嗯,非常直观的做法就是把"-"去掉,再比較大小,真的有必要吗?看以下最简单的时间比較方式: <!DOCT ...

  3. Web 目录枚举与遍历漏洞解决

    "目录枚举漏洞"解决方法 一.名词解释 网站目录枚举漏洞:指黑客利用非法攻击手段扫描符合"8.3"命名原则的目录与文件. 二.验证工具:scanner-comp ...

  4. python可hash 不可hash类型

    不可变类型是可hash #tuple str freezeset 可变类型是不可hash ##list set

  5. 微信小程序 - 如何通过button按钮实现分享(转发)功能

    小程序官方API https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html#%E9%A1%B5% ...

  6. WCF configure

    1. maxBufferSize 一个正整数,指定内存中用于存储消息的缓冲区的最大大小(字节). 如果 transferMode 属性等于 Buffered,则此属性应等于 maxReceivedMe ...

  7. R 介绍

    R定义:一个能够自由有效地用于统计计算和绘图的语言和环境,它提供了广泛的统计分析和绘图技术. R语言的使用很大程度上可以说是借助各种各种各样R包的辅助,从某种程度上说,运用R的插件来满足不同的需求. ...

  8. statusbar的颜色设置

    步骤一.在info.plist文件中添加一行(key:View controller-based status bar appearance,value:NO) 步骤二.在appDelegate中,添 ...

  9. js从$scope外部调用$scope内部函数,跨js调用非全局函数

    scope内部函数定义 //定位 $scope.LocateByPoint = function (x,y) { if(!x || !y) { window.alert("GPS坐标不存在, ...

  10. Oracle database datafile header中记录的datafile的大小

    本文的环境:Oracle Databae 12.1.0.2, rhel5.9 x86-64bit [oracle@rhel59 orcl]$ pwd /u01/app/oracle/oradata/o ...