当前位置: 代码网 > it编程>App开发>苹果IOS > iOS通过UIDocumentInteractionController实现应用间传文件

iOS通过UIDocumentInteractionController实现应用间传文件

2024年05月18日 苹果IOS 我要评论
引言话开篇:由于ios沙盒机制,app文件存储位置只能当前应用访问,这里简单记录一下用 uidocumentinteractioncontroller 实现app间传文件。一、实现效果两个 app ,

引言

话开篇:由于ios沙盒机制,app文件存储位置只能当前应用访问,这里简单记录一下用 uidocumentinteractioncontroller 实现app间传文件。

一、实现效果

两个 apptestprojecta 将文件通过 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应用间传文件的资料请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com