欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS通過(guò)UIDocumentInteractionController實(shí)現(xiàn)應(yīng)用間傳文件

 更新時(shí)間:2023年01月15日 11:57:46   作者:頭疼腦脹的代碼搬運(yùn)工  
這篇文章主要為大家介紹了iOS通過(guò)UIDocumentInteractionController實(shí)現(xiàn)應(yīng)用間傳文件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

引言

話開(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)文章

最新評(píng)論