iOS通過(guò)UIDocumentInteractionController實(shí)現(xiàn)應(yīng)用間傳文件
引言
話開(kāi)篇:由于iOS沙盒機(jī)制,APP文件存儲(chǔ)位置只能當(dāng)前應(yīng)用訪問(wèn),這里簡(jiǎn)單記錄一下用 UIDocumentInteractionController 實(shí)現(xiàn)APP間傳文件。
一、實(shí)現(xiàn)效果
兩個(gè) APP ,TestProjectA 將文件通過(guò) UIDocumentInteractionController 來(lái)傳遞到 TestProjectB
二、配置工程
要想通過(guò)系統(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、彈出文件其他打開(kāi)方式工具欄
APP-A
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileUrl]; self.documentInteractionController.delegate = self; [self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
2、接收文件
APP-B
其實(shí)這里的所說(shuō)的 "接收文件" 是有些不妥的,因?yàn)?,?dāng) AppDelegate 的方法里獲取到文件的沙盒路徑已經(jīng)是 APP-B 的了,這里只是拿來(lái)就用。
- (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//真機(jī) replaceStr = @"file:///private"; #endif NSString * filePathStr = [[NSString stringWithFormat:@"%@",url] stringByReplacingOccurrencesOfString:replaceStr withString:@""]; /** 業(yè)務(wù)邏輯 **/ } return YES; }
內(nèi)容僅為簡(jiǎn)單記錄,并不是什么新的技術(shù)。只是在開(kāi)發(fā)的時(shí)候需要時(shí)權(quán)當(dāng)個(gè)筆記。
以上就是iOS通過(guò)UIDocumentInteractionController實(shí)現(xiàn)應(yīng)用間傳文件的詳細(xì)內(nèi)容,更多關(guān)于iOS應(yīng)用間傳文件的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
IOS 通過(guò)tag刪除動(dòng)態(tài)創(chuàng)建的UIButton
這篇文章主要介紹了IOS 通過(guò)tag刪除動(dòng)態(tài)創(chuàng)建的UIButton的相關(guān)資料,需要的朋友可以參考下2017-03-03Flutter繪制3.4邊形及多邊形漸變動(dòng)畫實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Flutter繪制3.4邊形之多邊形漸變動(dòng)畫實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08ios 實(shí)現(xiàn)倒計(jì)時(shí)的兩種方式
這篇文章主要介紹了ios實(shí)現(xiàn)倒計(jì)時(shí)的兩種方式,第一種方式使用NSTimer來(lái)實(shí)現(xiàn),第二種方式使用GCD來(lái)實(shí)現(xiàn)。具體內(nèi)容詳情大家參考下本文2017-01-01iOS應(yīng)用UI開(kāi)發(fā)中的字體和按鈕控件使用指南
這篇文章主要介紹了iOS應(yīng)用UI開(kāi)發(fā)中的字體和按鈕控件使用指南,分別簡(jiǎn)單講解了UILabel和UIButton的用法,需要的朋友可以參考下2016-01-01IOS實(shí)現(xiàn)點(diǎn)擊滑動(dòng)抽屜效果
這篇文章主要為大家詳細(xì)介紹了IOS實(shí)現(xiàn)點(diǎn)擊滑動(dòng)抽屜效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-02-02iOS實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01iOS中給自定義tabBar的按鈕添加點(diǎn)擊放大縮小的動(dòng)畫效果
這篇文章主要介紹了iOS中給自定義tabBar的按鈕添加點(diǎn)擊放大縮小的動(dòng)畫效果的相關(guān)資料,非常不錯(cuò),具有參考解決價(jià)值,需要的朋友可以參考下2016-11-11