iOS - 通过共享扩展在应用程序之间移动项目

标签 ios swift file ios8-share-extension ios-app-group

有 2 个应用程序:

  1. WhatsApp 应用程序
  2. 我的应用程序(testAPP)

我尝试在 WhatsApp 和我的应用程序 (testAPP) 之间共享音频文件,我已经实现了 APP Group 和共享扩展。

我成功地在这些应用程序之间进行集成并收到一个网址,如下所示:

文件:///private/var/mobile/Containers/Data/Application/xxxxxx/tmp/documents/xxxxxx/2017-04-16-AUDIO-00001077.opus

例如,当我尝试将此文件移动到本地文档应用程序时,问题就开始了

目标路径: 起始路径 =/private/var/mobile/Containers/Data/Application/xxxxxx/tmp/documents/xxxxxx/2017-04-16-AUDIO-00001077.opus

目标路径: endingPath =/var/mobile/Containers/Data/Application/685A0D6F-AB7C-4DCF-ADD9-19AAE6A8DAFD/Documents

    do {
        try filemgr.moveItem(atPath: startingPath, toPath: endingPath!)
    } catch let error as NSError {
        NSLog("Unable to create directory \(error.debugDescription)")
    }

我收到此错误,但我不明白为什么

无法创建目录错误域=NSCocoaErrorDomain代码=516““2017-04-16-AUDIO-00001077.opus”无法移动到“xxxx”,因为同名的项目已存在。” UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/xxxxx/tmp/documents/xxxxxxx/2017-04-16-AUDIO-00001077.opus,NSUserStringVariant=( 移动 ),NSDestinationFilePath=/var/mobile/Containers/Data/Application/6xxxx/Documents,NSFilePath=/private/var/mobile/Containers/Data/Application/xxxxx/tmp/documents/xxxxxx2/2017-04-16-AUDIO- 00001077.opus,NSUnderlyingError=0x17005f6b0 {错误域=NSPOSIXErrorDomain代码=17“文件存在”}}

最佳答案

终于明白问题所在了。

当应用程序使用共享扩展名来共享应用程序内部的文件/图像...时,该文件存在于以下位置:

/private/var/mobile/Containers/Data/Application/

为了获得文件的完全权限,需要将文件复制到应用组共享文件夹:

/private/var/mobile/Containers/Shared/AppGroup/

将文件移动到应用组共享文件夹后,您将获得该文件的完全权限

关于iOS - 通过共享扩展在应用程序之间移动项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43438040/

相关文章:

ios - 如何清除iOS中的缓存?

java - 使用 Java、Apache Common Net 将文件通过 FTP 传输到大型机

android - 如何从 InputStream 而不是 File 获取 Exif 数据?

用于大文件上传的 PHP POST 和执行

javascript - 从 WKWebView 获取 JSON 文本

ios - Swift 中的全屏背景图像

ios - Swift:类型必须实现协议(protocol)并且是给定类的子类

ios - 如何在 Swift 中获取唯一的设备 ID?

ios - 候选不是 '@objc' 但协议(protocol)需要它

ios - UITableView 仅向下滚动