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. ConfigParser.MissingSectionHeaderError: File contains no section headers.

    今天使用ConfigParser解析一个ini文件,报出如下错误: config.read(logFile) File "C:\Python26\lib\ConfigParser.py&qu ...

  2. java byte转无符号int

    import java.io.ByteArrayInputStream; public class Test{ public static void main(String[] args) { byt ...

  3. 使用nginx部署Yii 2.0\yii-basic-app-2.0.5

    nginx.conf #user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/error.log noti ...

  4. 56. Edit Distance && Simplify Path

    Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert ...

  5. iOS开发--一些UITabBarItem属性的设置[转]

    1.改变UITabBarItem 字体颜色 [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionary dictionaryWithOb ...

  6. FW: javascripts 要不要加引号

    Javascript编程风格  http://www.ruanyifeng.com/blog/2012/04/javascript_programming_style.html 作者: 阮一峰 日期: ...

  7. TortoiseSVN 版本回滚

    尝试用TortoiseSVN进行版本回滚,回滚到的版本和实际的内容有出入,可能是点了太多次给点乱了,囧~ 不过发现一个比较靠谱的方法,如下: 右键点击文件TortoiseSVN->showlog ...

  8. android WebView问题

    1.加载本地js.css文件 今天碰到个问题,使用WebView加载html数据,本来没什么问题,loadUrl(),loadData(),都可以使用 但是如果需要引入本地的js.css文件就碰到问题 ...

  9. SSL协议(HTTPS) 握手、工作流程详解(双向HTTPS流程)

    原文地址:http://www.cnblogs.com/jifeng/archive/2010/11/30/1891779.html SSL协议的工作流程: 服务器认证阶段:1)客户端向服务器发送一个 ...

  10. Bootstrap 更改Navbar默认样式

    alt+shift+n 新建文件ctrl+shift+/ 注释ctrl+shift+f 重新排版代码ctrl+/ 注释 /* navbar */.navbar-default { background ...