这篇文章主要为大家介绍了iOS通过UIDocumentInteractionController实现应用间传文件示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
引言
话开篇:由于iOS沙盒机制,APP文件存储位置只能当前应用访问,这里简单记录一下用 UIDocumentInteractionController 实现APP间传文件。
一、实现效果

两个 APP ,TestProjectA 将文件通过 UIDocumentInteractionController 来传递到 TestProjectB
二、配置工程
要想通过系统 UIDocumentInteractionController 功能展示指定的APP,那么,需要在指定的工程 Info.plist 加入如下信息:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version="1.0" >
<dict>
<key> CFBundleDocumentTypes </key>
<array>
<dict>
<key> LSHandlerRank </key>
<string> Default </string>
<key> LSItemContentTypes </key>
<array>
<string> com.adobe.pdf </string>
<string> public.data </string>
<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>
</array>
</dict>
</array>
</dict>
</plist>
三、用法
1、弹出文件其他打开方式工具栏
APP-A
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileUrl];
self.documentInteractionController.delegate = self;
[self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
2、接收文件
APP-B
其实这里的所说的 "接收文件" 是有些不妥的,因为,当 AppDelegate 的方法里获取到文件的沙盒路径已经是 APP-B 的了,这里只是拿来就用。
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
if ([url.scheme isEqualToString:@"file"]) {
NSString * replaceStr;
#if TARGET_IPHONE_SIMULATOR//模拟器
replaceStr = @"file://";
#elif TARGET_OS_IPHONE//真机
replaceStr = @"file:///private";
#endif
NSString * filePathStr = [[NSString stringWithFormat:@"%@",url] stringByReplacingOccurrencesOfString:replaceStr withString:@""];
/** 业务逻辑 **/
}
return YES;
}
内容仅为简单记录,并不是什么新的技术。只是在开发的时候需要时权当个笔记。
以上就是iOS通过UIDocumentInteractionController实现应用间传文件的详细内容,更多关于iOS应用间传文件的资料请关注编程学习网其它相关文章!
本文标题为:iOS通过UIDocumentInteractionController实现应用间传文件
基础教程推荐
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- Android多返回栈技术 2023-04-15
- Android中的webview监听每次URL变化实例 2023-01-23
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- android studio按钮监听的5种方法实例详解 2023-01-12
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Flutter手势密码的实现示例(附demo) 2023-04-11
