iOS调用文件app(file.app)选择文件和下载
第三方应用调用系统文件app,并下载文件。
###配置如下
1:证书文件配置
在Identifiers下创建你的iCloud Containers配置,点击“+”创建
2:在Identifiers下选择你要添加icloud的boundid把icloud配置勾选上既可
3:打开工程中的配置如下
4:可选配置
在info.plist中添加如下两个配置
Supports opening documents in place
Application supports iTunes file sharing
结果都为YES
设置完以后,会在文件app中有一个和你工程名相同的文件夹出现。
5:打开文件app
- (void)presentDocumentCloud {NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code ", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];documentPickerViewController.delegate = self;[self presentViewController:documentPickerViewController animated:YES completion:nil];
}
遵守代理如下
<UIDocumentPickerDelegate, UIDocumentInteractionControllerDelegate>
选择文件事件
#pragma mark - UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {NSArray *array = [[url absoluteString] componentsSeparatedByString:@"/"];NSString *fileName = [array lastObject];fileName = [fileName stringByRemovingPercentEncoding];NSLog(@"--->>>>%@",fileName);if ([iCloudManager iCloudEnable]) {[iCloudManager downloadWithDocumentURL:url callBack:^(id obj) {NSData *data = obj;UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"icloud" message:@"写入沙河" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];[alert show];//写入沙盒DocumentsNSString *path = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@",fileName]];[data writeToFile:path atomically:YES];}];}
}
6:判断icloud是否可用
+ (BOOL)iCloudEnable {NSFileManager *manager = [NSFileManager defaultManager];NSURL *url = [manager URLForUbiquityContainerIdentifier:nil];if (url != nil) {return YES;}NSLog(@"iCloud 不可用");UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"icloud" message:@"iCloud 不可用" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];[alert show];return NO;
}
下载工程
有些地方说的不到位,还请各位看官指正。。。
- 也可以添加洲洲哥的微信公众号
可以来微信公众号(洲洲哥)后台给我们留言。 快来扫码关注我们吧!
iOS调用文件app(file.app)选择文件和下载相关推荐
- layui动态渲染上传文件功能点击选择文件没反应解决方案
layui动态渲染上传文件功能点击选择文件没反应解决方案 场景 动态加载出来的table表格 如下表格 问题 点击选择多文件没有反应 不弹出选择文件的弹框 如果你和我是同样问题 请向下继续看 如果不同 ...
- uniapp 打包app后,选择文件上传时,编辑上传文件
uniapp打包app后,业务需求有个一个需要上传文件的需求,因此需要查找手机的本地文件,但是uni.chooseFile(OBJECT)这个api无法作用在app上,因此在插件市场找到的了别人写好的 ...
- iOS 调用私有函数安装app 卸载 app
1.环境 1.OS X EI Caption 10.11.1 & Xcode 7 2.Xcode安装Command Line Tools 3.iPhone 安装AppSync 2.Mobile ...
- input type=file 获取选择文件名称、路径方法及input上传按钮美化
获取文件名 document.getElementById('upload').files[0].name; 获取文件路径 document.getElementById('upload').valu ...
- cad vba 打开文件对话框_AutoCAD VBA选择文件夹的代码
'AutoCAD VBA 选择文件夹的代码 ' 流沙之泉编写于 2018 年 11 月 30 日,于 AutoCAD2017 64 位上测试通过. ' 将此份文档另存为纯文本格式文件 MdFileBr ...
- linux c文件操作,C语言文件操作(FILE)与常用文件操作函数
文件 1.文件基本概念 C程序把文件分为ASCII文件和二进制文件,ASCII文件又称文本文件,二进制文件和文本文件(也称ASCII码文件)二进制文件中,数值型数据是以二进制形式存储的, 而在文本文件 ...
- 文件操作(FILE)与常用文件操作函数——C语言
文件 1.文件基本概念 C程序把文件分为ASCII文件和二进制文件,ASCII文件又称文本文件,二进制文件和文本文件(也称ASCII码文件)二进制文件中,数值型数据是以二进制形式存储的, 而在文本文件 ...
- 创建文件java_Java File.createNewFile 创建文件
首页 > 基础教程 > IO流 > File类 Java File.createNewFile 创建文件 定义 public boolean createNewFile() 返回 会 ...
- iOS调用 AlipaySDK 支付宝找不到头文件openssl/rsa.h 的解决方案
2019独角兽企业重金招聘Python工程师标准>>> 1. 首先确认 openssl 和 Util目录已经添加到Build setting的 header search path中 ...
最新文章
- Ubuntu 14.04安装搜狗拼音linux版应该注意的问题
- stm32 图像处理_假如STM32也有朋友圈
- SQL Server2012 安装方法
- 自定义PopView
- 内存墙,多核CPU的终结者?
- 动态html树形菜单模板,JS+CSS简易树状菜单Tree
- mysq命令行导出sql_mysql利用命令导出数据sql语句
- 谁适合做Scrum Master?
- Centos磁盘管理和文件系统管理
- 拓端tecdat|R语言基于树的方法:决策树,随机森林,Bagging,增强树
- python生成条形码和二维码
- 从球衣了解“红魔”曼联历史
- GitHub 优秀的 Android 开源项目第二篇——转自多篇网络文章
- 计算机考研培训中公,计算机408
- 怎么SSH远程连接云服务器
- 域名 空间 服务器 三者之间的关系
- Youtube到底怎么读?你读对了吗?
- 外屏和宽屏浪费了?HarmonyOS折叠屏设计规范教你用起来
- 真实案例:网站遭遇DOS攻击
- python画球鞋_基于Python爬虫原理的篮球鞋选择程序的设计与实现