有 2 个应用程序:
- WhatsApp 应用程序
- 我的应用程序(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/