iOS App让自己的应用在其它应用中打开列表中显示
像百度网盘等应用,里面的文件打开时,都能够通过以下应用再打开文件。以下红色框框内的我的jpg就是我做的一个样例。
由于样例没有提供Icon,所以显示的是默认icon。
以下就是这样例的主要步骤和代码。
样例是一个打开jpg图片程序。
1、在项目的**info.plist文件里加入:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>icon@2x.png</string>
<string>icon.png</string>
</array>
<key>CFBundleTypeName</key>
<string>Molecules Structure File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.fzrong.jpg</string>
<string>org.gnu.gnu-zip-archive</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.plain-text</string>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>Molecules Structure File</string>
<key>UTTypeIdentifier</key>
<string>com.fzrong.jpg</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>jpg</string>
<key>public.mime-type</key>
<string>image/jpg</string>
</dict>
</dict>
</array>
这就是告诉系统,你能打开 jpg这个文件类型。
2、打开到自己的app时,要截取到过来资源的文件路径:
在Appdelegate里加入代码例如以下:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url != nil) {
NSString *path = [url absoluteString];
NSMutableString *string = [[NSMutableString alloc] initWithString:path];
if ([path hasPrefix:@"file://"]) {
[string replaceOccurrencesOfString:@"file://" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, path.length)];
}
[self.viewController openPng:string];
}
return YES;
}
要去掉file://文件路径的头。要不然找不到资源。
3、在自己的ViewController里打开jgp显示:
- (void)openPng:(NSString*)string
{
UIImage *image = [[UIImage alloc] initWithContentsOfFile:string];
float width = image.size.width;
float height = image.size.height;
if (width > 320) {
height = (height/width) * 300;
width = 300;
}
CGRect frame = CGRectMake(0, 20, width, height);
imageView.frame = frame;
imageView.image = image;
}
打开之后的效果是这种:
注意:这都是在真机上演示的。
这里样例咱们能够扩展,怎么打开网盘里的gif图片啊。还有其它自己自己定义的格式也能够。
项目完整代码已经上传到:http://download.csdn.net/detail/totogo2010/7460929
或者github: https://github.com/schelling/openFileType
參考:
https://developer.apple.com/library/ios/qa/qa1587/_index.html
http://stackoverflow.com/questions/20869815/open-file-from-local-file-system-with-default-application-ios
iOS App让自己的应用在其它应用中打开列表中显示的更多相关文章
- 在app中打开appStore中其他app
var str = "https://itunes.apple.com/cn/app/zhang-jiange-hao-tou-zi-ke/id402382976?mt=8"//这 ...
- Vim 写 iOS App
Vim 写 iOS App 我们都知道 Vim 和 Emacs 都是文本编辑器中的上古神器,你也许用 ctags,cscopes 配合 Vim 完成过大型 C 或者 C++ 的开发,你也许配合过其他插 ...
- iOS app内存分析套路
iOS app内存分析套路 Xcode下查看app内存使用情况有2中方法: Navigator导航栏中的Debug navigator中的Memory Instruments 一.Debug navi ...
- iOS App引导页功能实现
一.写作原因 以前都没有想着来写点东西,今天遇到件事情让我决定每次还是要做记录.因为以前自己可以轻松的完成pod spec的配置,但是今天在做的时候还是忘了遇到了很多坑.pod spec配置遇到的坑不 ...
- iOS APP 如何做才安全
本来 写了一篇<iOS 如何做才安全--逆向工程 - Reveal.IDA.Hopper.https抓包 等>,发现文章有点杂,并且“iOS 如何做才安全”这部分写的越来越多,觉得 分出来 ...
- Xcode7.1环境下上架iOS App到AppStore 流程② (Part 二)
前言部分 part二部分主要讲解 iOS App IDs 的创建.概要文件的配置.以及概要文件安装的过程. 一.iOS App IDs 的创建 1)进入如图1所示界面点击右上角箭头所指的加号 进入iO ...
- iOS App上架流程(2016详细版)
iOS App上架流程(2016详细版) 原文地址:http://www.jianshu.com/p/b1b77d804254 感谢大神整理的这么详细 一.前言: 作为一名iOSer,把开发出来的Ap ...
- 用Model-View-ViewModel构建iOS App(转)
转载自 Model-View-ViewModel for iOS [译] 如果你已经开发一段时间的iOS应用,你一定听说过Model-View-Controller, 即MVC.MVC是构建iOS a ...
- 用Model-View-ViewModel构建iOS App
如果你已经开发一段时间的iOS应用,你一定听说过Model-View-Controller,即MVC.MVC是构建iOS App的标准模式.然而,最近我已经越来越厌倦MVC的一些缺点.在本文,我将重温 ...
随机推荐
- 大数据学习笔记03-HDFS-HDFS组件介绍及Java访问HDFS集群
HDFS组件概述 NameNode 存储数据节点信息及元文件,即:分成了多少数据块,每一个数据块存储在哪一个DataNode中,每一个数据块备份到哪些DataNode中 这个集群有哪些DataNode ...
- duilib进阶教程 -- Container控件 (3)
前面两个教程的目的是教大家与MFC结合,那么从这篇起,将不再使用MFC,而使用纯win32项目,本文的所有知识已经在<duilib入门教程>里面讲过了,因此基础知识不再赘述. 代码下载:h ...
- [Bayes] Point --> Hist: Estimate "π" by R
Verify the Monte Carlo sampling variability of "π". p = π/4 与 所得 0.7854 比较接近,故满足 Central L ...
- Hadoop -- HDFS 读写数据
一.HDFS读写文件过程 1.读取文件过程 1) 初始化FileSystem,然后客户端(client)用FileSystem的open()函数打开文件 2) FileSyst ...
- 我的第一篇paper
找实习虽然只为自己争取到一个秋季的绿色通道,但可喜的是,我投的几篇paper,终于中了一篇. 现在可以在英文数据库或google scholar上面搜索到自己名字,感觉很nice,研究生的心愿算是完成 ...
- Apache Maven 打包可执行jar
在本文的 参考资料 部分,您将发现大量介绍 Maven 的入门教程.本文的 5 个技巧目的是帮助您解决即将出现的一些问题:使用 Maven 管理您的应用程序的生命周期时,将会出现的编程场景. 1. 可 ...
- 5.STM32通用定时器TIM3中断
1.通用定时器TIM3中断 #include "timer.h" #include "led.h" void TIM3_Int_Init(u16 arr,u16 ...
- day_5.26python动态添加属性和方法
python动态添加属性和方法 既然给类添加⽅法,是使⽤ 类名.⽅法名 = xxxx ,那么给对象添加⼀个⽅法 也是类似的 对象.⽅法名 = xxx '''2018-5-26 13:40:09pyth ...
- B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
- Linux目录结构及文件基本操作
作业: 1.创建一个homework目录,在该目录下新建名为1.txt~10.txt的文件 2.删除1.txt~5.txt 代码: mkdir homework cd homework touch { ...