iOS让自己的App在其他应用中打开列表中显示
来源:互联网 发布:c语言类型强制转换 编辑:程序博客网 时间:2024/05/09 02:15
像百度网盘等应用,里面的文件打开时,都可以通过以下应用再打开文件。下面红色框框内的我的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>
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图片啊,还有其他自己自定义的格式也可以。
或者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
0 0
- iOS App让自己的应用在其他应用中打开列表中显示
- iOS App让自己的应用在其他应用中打开列表中显示
- iOS让自己的App在其他应用中打开列表中显示
- iOS App让自己的应用在其他应用中打开列表中显示、iOS把自己的应用添加到”活动“、将PDF文件Open In MyApp
- iOS App让自己的应用在其他应用中打开列表中显示、iOS把自己的应用添加到”活动“、将PDF文件Open In MyApp
- ios App 让自己的应用在其他应用打开列表显示
- 让自己的应用在其他应用中打开列表中显示
- 让自己的应用在其他应用中打开列表中显示
- iOS 让自己的应用 在其他应用中打开
- 实现让你的应用在其他应用中文件的打开方式列表中显示
- 让自己的app出现在某类格式文件的默认打开列表中
- iOS将本应用添加在‘其他方式打开’的列表中
- 在自己的app中调用其他浏览器显示网页
- 在unity中打开ios手机上的其他app
- Android 仿照第三方app 将自己APP显示在打开列表中
- 【IOS】在SDK中打开其他接入应用的解决方案
- iOS在SDK中打开其他接入应用的解决方案
- 在自己的app中打开应用设置界面
- 轻松使用xmlpull解析xml
- Android中轴旋转特效实现,制作别样的图片浏览器
- 几十种编程语言的快速入门教程
- 开转产品经理(汇总意见)
- jni converting jstring to char *
- iOS让自己的App在其他应用中打开列表中显示
- MySql处理数据库和表
- Android点击效果改变字体颜色
- AndroidManifest.xml中application name功能介绍
- 长期收购无限极完美回收玫琳凯天狮中脉三生如新太阳神13570872922
- c++整理(1)
- 黑马程序员_面向对象(1)
- 广播检测网络状态的改变
- Http,Https (SSL)的Url绝对路径,相对路径解决方案Security Switch 4.2 中文帮助文档