IOS 可以复制超过 300MB 的本地文件吗?
Can IOS copy local file over 300MB?
向全世界每一位优秀的开发者问好!
我想做的是将数据库文件从主应用程序包复制到 IOS 文档文件夹,代码看起来不错,但总是无法复制文件,目标文件始终为零字节!
所以,错误的是下面的代码!
Swift 5
private func moveDbFile() {
let fileManager = FileManager.default
let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
print(documentsDirectory)
guard let sourcePath = Bundle.main.path(forResource: "database", ofType: "db") else {
return
}
if fileManager.fileExists(atPath: sourcePath) {
let sourceUrl = URL(fileURLWithPath: sourcePath)
let destination = documentsDirectory.appendingPathComponent("database.db", isDirectory: false)
try? fileManager.copyItem(at: sourceUrl, to: destination)
if fileManager.fileExists(atPath: destination.path) {
print("file copied")
} else {
print("file copy failed")
}
}
}
已通过将数据库文件添加到项目目标成员资格来修复
向全世界每一位优秀的开发者问好!
我想做的是将数据库文件从主应用程序包复制到 IOS 文档文件夹,代码看起来不错,但总是无法复制文件,目标文件始终为零字节! 所以,错误的是下面的代码!
Swift 5
private func moveDbFile() {
let fileManager = FileManager.default
let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
print(documentsDirectory)
guard let sourcePath = Bundle.main.path(forResource: "database", ofType: "db") else {
return
}
if fileManager.fileExists(atPath: sourcePath) {
let sourceUrl = URL(fileURLWithPath: sourcePath)
let destination = documentsDirectory.appendingPathComponent("database.db", isDirectory: false)
try? fileManager.copyItem(at: sourceUrl, to: destination)
if fileManager.fileExists(atPath: destination.path) {
print("file copied")
} else {
print("file copy failed")
}
}
}
已通过将数据库文件添加到项目目标成员资格来修复