iOS通過UIDocumentInteractionController實現(xiàn)應(yīng)用間傳文件
引言
話開篇:由于iOS沙盒機制,APP文件存儲位置只能當前應(yīng)用訪問,這里簡單記錄一下用 UIDocumentInteractionController 實現(xiàn)APP間傳文件。
一、實現(xiàn)效果

兩個 APP ,TestProjectA 將文件通過 UIDocumentInteractionController 來傳遞到 TestProjectB
二、配置工程
要想通過系統(tǒng) 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 的方法里獲取到文件的沙盒路徑已經(jīng)是 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:@""];
/** 業(yè)務(wù)邏輯 **/
}
return YES;
}
內(nèi)容僅為簡單記錄,并不是什么新的技術(shù)。只是在開發(fā)的時候需要時權(quán)當個筆記。
以上就是iOS通過UIDocumentInteractionController實現(xiàn)應(yīng)用間傳文件的詳細內(nèi)容,更多關(guān)于iOS應(yīng)用間傳文件的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
IOS 通過tag刪除動態(tài)創(chuàng)建的UIButton
這篇文章主要介紹了IOS 通過tag刪除動態(tài)創(chuàng)建的UIButton的相關(guān)資料,需要的朋友可以參考下2017-03-03
Flutter繪制3.4邊形及多邊形漸變動畫實現(xiàn)示例
這篇文章主要為大家介紹了Flutter繪制3.4邊形之多邊形漸變動畫實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08
iOS應(yīng)用UI開發(fā)中的字體和按鈕控件使用指南
這篇文章主要介紹了iOS應(yīng)用UI開發(fā)中的字體和按鈕控件使用指南,分別簡單講解了UILabel和UIButton的用法,需要的朋友可以參考下2016-01-01
iOS中給自定義tabBar的按鈕添加點擊放大縮小的動畫效果
這篇文章主要介紹了iOS中給自定義tabBar的按鈕添加點擊放大縮小的動畫效果的相關(guān)資料,非常不錯,具有參考解決價值,需要的朋友可以參考下2016-11-11

