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文件作为入 ...
随机推荐
- Runloop基础知识
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- Spark Streaming、Kafka结合Spark JDBC External DataSouces处理案例
场景:使用Spark Streaming接收Kafka发送过来的数据与关系型数据库中的表进行相关的查询操作: Kafka发送过来的数据格式为:id.name.cityId,分隔符为tab zhangs ...
- php 向asmx发送请求 || php 发送xml请求, 以及处理返回的xml结果
var $live_url = 'https://processing.ukash.com/RPPGateway/process.asmx'; $source = array( 'SecurityTo ...
- DOCTYPE 中xhtml 1.0和 html 4.01区别分析
前者相对于后者有以下特性: 1.所有的标记都都要闭合 所有的标记都要闭合,如果是单独不成对的标签,在标签最后加一个"/"来关闭它.例如: <h6>close tag & ...
- Qlikview 的服务器
服务器管理 1 , Create a job 1.1 转到 Documents 分页 1.2 从左边目录搜索到 需要执行Job的qvw报表,如 "getting start.qvw" ...
- The Magic only works with total devotion of one's heart
The Magic only works with total devotion of one's heart All tools and equipments are useless without ...
- Linux操作系统奥秘02-系统引导(GRUB)
GRUB的加载流程 GRUB是GNU的一款多重引导软件.GRUB包含了3个重要的文件:stage1 ,e2fsstage1_5,stage2.这三个文件分别代表了GRUB运行的3个阶段. 1.stag ...
- apache-jmeter学习文档
http://www.cnblogs.com/TankXiao/p/4045439.html#sampler
- 生产者消费者模式--阻塞队列--LOCK,Condition--线程池
1.阻塞队列:http://www.cnblogs.com/dolphin0520/p/3932906.html 2.Condition 生产者消费者实现 :http://www.cnblogs.co ...
- left join ,right join ,inner join ,cross join 区别
left join ,right join ,inner join ,cross join 区别(参考:http://zhidao.baidu.com/link?url=gpOl9HXZR0OrQuy ...