![](/img/trans.png)
[英]carthage,couldn’t be copied because you don’t have permission to access “Release-iphoneos”
[英]couldn’t be copied because you don’t have permission to access application bundle in ios
当我将文件从文件目录复制到应用程序包目录时,它会给出如下错误:
无法复制“图像”,因为您无权访问“资源”。
我的代码
let fileManager = FileManager.default
let documentDirectoryPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("Images")
let bundleDirectoryPath = (Bundle.main.resourceURL?.appendingPathComponent("GCDWebUploader.bundle").appendingPathComponent("Contents").appendingPathComponent("Resources").appendingPathComponent("Images"))
do {
try fileManager.copyItem(at: documentDirectoryPath!, to: bundleDirectoryPath!)
} catch let error as NSError {
print("Couldn't copy file to final location! Error:\(error.description)")
}
为什么要复制到Bundle Dirctory ..没有办法在bundle目录中写入,因为bundle dir是使用SSL certificate
签名的代码,你不能破坏它。 您可以使用文档目录本身来存储文件。
磁盘上的bundle目录( 在这里读取)是代码不可变的,即开发人员不能更改其内容。 应用程序的文档目录(沙箱)是您要保留的位置。
如果要将任何文件添加到bundle目录,则必须在构建时使用构建阶段选项卡中的复制资源完成。 这些通常是每次执行都不应更改的文件。
如果您尝试添加到捆绑包的图像是用于UI。 使用资产目录
对于任何其他类型的文件(读取或写入),请使用文档目录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.