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打开文件的更多相关文章

  1. 使用vue打包,vendor文件过大,或者是app.js文件很大

    我的解决办法: 1.把不常改变的库放到index.html中,通过cdn引入,比如下面这样: 然后找到build/webpack.base.conf.js文件,在 module.exports = { ...

  2. Window系统命令行调用控制面板程序

    Window系统命令行调用控制面板程序 control.exe /name microsoft.folderoptions 启动资源管理器的 文件夹属性 选项卡 control.exe /name M ...

  3. C#调用Exe程序示例

    在编写程序时经常会使用到调用可执行程序的情况,本文将简单介绍C#调用exe的方法.在C#中,通过Process类来进行进程操作. Process类在System.Diagnostics包中. 示例一 ...

  4. 微信小程序app.json文件常用全局配置

    小程序根目录下的 app.json 文件用来对微信小程序进行全局配置,决定页面文件的路径.窗口表现.设置网络超时时间.设置多 tab 等. JOSN文件不允许注释,下面为了学习加上注释,粘贴需要的片段 ...

  5. APP打开(二)—标准流程

    APP打开是一个老生常谈的话题,在互联网时代,在APP遍地的时代,APP打开是每一个APP的必经之路,今天我想通过以下几点来阐述APP打开的标准流程,给这个话题写一点自己的见解. APP打开现状 标准 ...

  6. iOS APP中第三方APP调用自己的APP,打开文件

    根据需求需要在项目中要打开word.pdf.excel等文件,在info.plist文件中添加 <key>CFBundleDocumentTypes</key> <arr ...

  7. android 程序打开第三方程序

    因为在开发过程中需要开启扫描第三方程序,并且点击启动的效果,所以对这个功能进行了实现,并且分享出来个大家. 之前看到网上说需要获取包名和类名,然后通过  intent 才能打开这个程序,其实不必要这样 ...

  8. 关于用python作为第三方程序,来调用shell命令的问题,以及返回值格式解析

    1.用python语言作为第三方,调用shell 在python2.x中,可以通过包commands来进行调用shell命令.如下: cmd就是你要调用的shell命令,把环境配置好,输入正确的命令格 ...

  9. Java项目导出为jar包+导出第三方jar包+使用命令行调用+传参

    Java项目导出为jar包+导出第三方jar包+使用命令行调用+传参 一.打包 情况1:不需要向程序传参数,并且程序没有使用第三方jar包 Eclipse上导出jar: 然后选择一个java文件作为入 ...

随机推荐

  1. JAVA设计模式之工厂方法模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述工厂方法模式的: 工厂方法模式是类的创建模式,又叫做虚拟构造子(Virtual Constructor)模式或者多态性工厂(Polymor ...

  2. strong & weak

    Here is a quick summary: A strong reference will keep the object it points to from being deallocated ...

  3. 1.No MBR错误

    如果提示如下错误: Error: No MBR is found at SD/MMC.                                              Hint: use f ...

  4. Java中的字符串常量池

    ava中字符串对象创建有两种形式,一种为字面量形式,如String str = "droid";,另一种就是使用new这种标准的构造对象的方法,如String str = new ...

  5. MsSqlServer 复制分发概述

    Replication方案可以分为Snapshot Replication, Transactional Replication, Peer-2-Peer Replication, Merge Rep ...

  6. hive中order by,sort by, distribute by, cluster by作用以及用法

    1. order by     Hive中的order by跟传统的sql语言中的order by作用是一样的,会对查询的结果做一次全局排序,所以说,只有hive的sql中制定了order by所有的 ...

  7. redis info参数详解

    redis 127.0.0.1:6381> info redis_version:2.4.16                                  # Redis 的版本redis ...

  8. 【转载】H264--2--语法及结构

    名词解释 场和帧 :    视频的一场或一帧可用来产生一个编码图像.在电视中,为减少大面积闪烁现象,把一帧分成两个隔行的场. 片:             每个图象中,若干宏块被排列成片的形式.片分为 ...

  9. 初尝 JFinal 项目(一)

    temp1: JFinal项目与JAVA项目类似,有属性方法.操作方法.Sql语句操作.jdbc.配置文件 对比:|| JAVA: Bean / Srv(Server) / SqlMap / jdbc ...

  10. Framework7--Test

    <!doctype html> <html> <head> <title>{{title}}</title> <meta charse ...