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的一些缺点.在本文,我将重温 ...
随机推荐
- react给一个div行内加背景图片并实现cover覆盖模式居中显示
具体background简写可以参考这篇文章. 这里注意,如果简写里要写background-size,则这里必须写 / ,否则整个背景图片样式没有解析出来. 它和font以及border-radi ...
- 【QT】打开文件对话框,选择路径下文件
0.头文件中加入 public: QString fileName; public slots: void showImage(); 1.添加两个头文件 #include<qfiledialog ...
- 10享元模式Flyweight
一.什么是享元模式 Flyweight模式也叫享元模式,是构造型模式之 一,它通过与其他类似对象共享数据来减小内存 占用. 二.享元模式的结构 三.享元模式的角色和职责 抽象享元角色: 所有具体享元类 ...
- redis最大缓存和回收策略
- A - 小孩报数问题
有N个小孩围成一圈,给他们从1开始依次编号,现指定从第W个开始报数,报到第S个时,该小孩出列,然后从下一个小孩开始报数,仍是报到S个出列,如此重复下去,直到所有的小孩都出列(总人数不足S个时将循环报数 ...
- Web(一)
Tomcat 服务器 B/S 浏览器/服务器 C/S 客户端/服务器 URI :大 广 /项目名 URL: 小 http://lo ...
- asp:LinkBtton PostBackUrl 中文乱码
这个也不行: HttpUtility.UrlEncode("中文") 替代方案为:<asp:HyperLink NavigateUrl=“~/路径” Target=" ...
- 洛谷P1433 吃奶酪【dfs】【剪枝】
题目:https://www.luogu.org/problemnew/show/P1433 题意: 给定n个坐标,要求从(0,0)开始走遍所有点,最少经过的路程. 思路: 刚开始想像数字三角形一样适 ...
- [No0000115]打开Excel2016提示内存或磁盘空间不足的解决方法
症状: 法一:右键文件,并 解除锁定: 法二: 在系统的服务中查看Windows Firewall服务 和Windows Update服务是否开启,如果没有开启就把他们启动一下. 1.在桌面的[计算机 ...
- Exception 07 : org.hibernate.LazyInitializationException: could not initialize proxy - no Session
异常名称: org.hibernate.LazyInitializationException: could not initialize proxy - no Session 异常截图: 异常详情: ...