ios调用第三方程序打开文件,以及第三方调用自己的APP打开文件
1.自己的APP调用第三方打开文件
主要是使用 UIDocumentInteractionController 类 并实现 UIDocumentInteractionControllerDelegate 的代理方法
@interface HNDownFileViewController ()<UIDocumentInteractionControllerDelegate> @property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController; @end - (void)viewDidLoad {
[super viewDidLoad];
//url 为需要调用第三方打开的文件地址
NSURL *url = [NSURL fileURLWithPath:_dict[@"path"]];
_documentInteractionController = [UIDocumentInteractionController
interactionControllerWithURL:url];
[_documentInteractionController setDelegate:self]; [_documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
需要在真机上调试,例子中打开的是 doc文件,如果手机上装了WPS或者office套件,就能调用这些应用打开。
2.第三方APP调用自己的APP,打开文件
在info.plist中添加如下代码
<array>
<dict>
<key>CFBundleTypeName</key>
<string>com.myapp.common-data</string>
<key>LSItemContentTypes</key>
<array>
<string>com.microsoft.powerpoint.ppt</string>
<string>public.item</string>
<string>com.microsoft.word.doc</string>
<string>com.adobe.pdf</string>
<string>com.microsoft.excel.xls</string>
<string>public.image</string>
<string>public.content</string>
<string>public.composite-content</string>
<string>public.archive</string>
<string>public.audio</string>
<string>public.movie</string>
<string>public.text</string>
<string>public.data</string>
</array>
</dict>
</array>
这在系统中添加了参数,如果有以上类型的文件,第三方应用可以调用我们的APP进行操作。
在第三方调用我们的APP后,会调用如下方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
{
if (self.window) {
if (url) {
NSString *fileNameStr = [url lastPathComponent];
NSString *Doc = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/localFile"] stringByAppendingPathComponent:fileNameStr];
NSData *data = [NSData dataWithContentsOfURL:url];
[data writeToFile:Doc atomically:YES];
[XCHUDTool showOKHud:@"文件已存到本地文件夹内" delay:2.0f];
}
}
return YES;
}
url 就是第三方应用调用时文件的沙盒地址,
@"Documents/localFile" 表示本地文件夹目录
sourceApplication 是调用我们APP的第三方应用是谁
我们把url传到我们需要用的界面
可以使用路径查看保存到本地的文件
ios调用第三方程序打开文件,以及第三方调用自己的APP打开文件的更多相关文章
- 使用vue打包,vendor文件过大,或者是app.js文件很大
我的解决办法: 1.把不常改变的库放到index.html中,通过cdn引入,比如下面这样: 然后找到build/webpack.base.conf.js文件,在 module.exports = { ...
- Window系统命令行调用控制面板程序
Window系统命令行调用控制面板程序 control.exe /name microsoft.folderoptions 启动资源管理器的 文件夹属性 选项卡 control.exe /name M ...
- C#调用Exe程序示例
在编写程序时经常会使用到调用可执行程序的情况,本文将简单介绍C#调用exe的方法.在C#中,通过Process类来进行进程操作. Process类在System.Diagnostics包中. 示例一 ...
- 微信小程序app.json文件常用全局配置
小程序根目录下的 app.json 文件用来对微信小程序进行全局配置,决定页面文件的路径.窗口表现.设置网络超时时间.设置多 tab 等. JOSN文件不允许注释,下面为了学习加上注释,粘贴需要的片段 ...
- APP打开(二)—标准流程
APP打开是一个老生常谈的话题,在互联网时代,在APP遍地的时代,APP打开是每一个APP的必经之路,今天我想通过以下几点来阐述APP打开的标准流程,给这个话题写一点自己的见解. APP打开现状 标准 ...
- iOS APP中第三方APP调用自己的APP,打开文件
根据需求需要在项目中要打开word.pdf.excel等文件,在info.plist文件中添加 <key>CFBundleDocumentTypes</key> <arr ...
- android 程序打开第三方程序
因为在开发过程中需要开启扫描第三方程序,并且点击启动的效果,所以对这个功能进行了实现,并且分享出来个大家. 之前看到网上说需要获取包名和类名,然后通过 intent 才能打开这个程序,其实不必要这样 ...
- 关于用python作为第三方程序,来调用shell命令的问题,以及返回值格式解析
1.用python语言作为第三方,调用shell 在python2.x中,可以通过包commands来进行调用shell命令.如下: cmd就是你要调用的shell命令,把环境配置好,输入正确的命令格 ...
- Java项目导出为jar包+导出第三方jar包+使用命令行调用+传参
Java项目导出为jar包+导出第三方jar包+使用命令行调用+传参 一.打包 情况1:不需要向程序传参数,并且程序没有使用第三方jar包 Eclipse上导出jar: 然后选择一个java文件作为入 ...
随机推荐
- NserviceBus+rabbitmq
Ok so I figured this out after looking a bit at the code and the requirements for amqp URI and it sh ...
- 1.date 命令
转自:http://www.cnblogs.com/peida/archive/2012/12/13/2815687.html 在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用 ...
- hbase运行shell时ERROR:org.apache.hadoop.hbase.PleaseHoldException: Master is initializing 的解决办法
这个问题困扰了我一天多的时间,百度搜索的前几条的答案也是很扯淡的,说什么把/etc/hosts文件下的127.0.1.1改成127.0.0.1就行了,我也只能呵呵了.今天早上起得很晚,中午迪哥请我们去 ...
- APP自适应的例子
<!DOCTYPE html><html lang="zh"> <head> <meta charset="UTF-8" ...
- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...
- 如何定义DATATABLE,同时赋值
//定义一个Table DataTable dt=new DataTable("yeji"); DataRow dr; DataColumn dc; //添加第0列 dc=new ...
- python基础07 函数
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 函数最重要的目的是方便我们重复使用相同的一段程序. 将一些操作隶属于一个函数,以后 ...
- Unknow Unknow
Unknow Unknow,讲的大概意思是:你不知道这事情的时候,那么请不要轻易下任何结论.例如,这个太难了,放弃吧.嗯,这个是捷径.而最后却是,困难的路越走越容易,容易的路越走越难.只是一种常见的现 ...
- jQuery 根据JSON数据动态生成表格
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- linux 服务器登录显示lastlogin
1.参数修改: /etc/ssh/sshd_config 问价里边的 printlastlog 设置为yes /etc/ssh/sshd_config 问价里边的 printmotd 设置为yes 2 ...