问题描述
我一直在浪费很多时间来解决这个问题。我正在尝试将文件写入iCloud驱动器。该代码似乎成功,并且当我以编程方式检查该文件是否存在时,它确实存在。我也可以在本地系统目录中找到它,但在“文件”应用程序或iCloud.com上却找不到。我尝试增加内部版本号和版本号并更改捆绑包标识符。我也已正确登录iCloud。
第一次在新设备上使用该应用程序显示该文件不存在,但是第二次显示该文件在写入文件之前和之后均存在,这与预期的一样。它只是从未显示在本地文件系统(而不是iCloud)之外的任何地方。我想念什么?
./programName -f directoryName
info.plist文件的部分
import Foundation
func saveFile(file: String)
{
if let dir = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")
{
do
{
if !FileManager.default.fileExists(atPath: dir.path)
{
try FileManager.default.createDirectory(at: dir,withIntermediateDirectories: false,attributes: nil)
}
let fileURL = dir.appendingPathComponent(file + ".json")
if !FileManager.default.fileExists(atPath: fileURL.path)
{
print("(a) File not found")
} else
{
print("(a) File found")
}
let string = "Mary had a little lamb"
try string.write(to: fileURL,atomically: false,encoding: .utf8)
if !FileManager.default.fileExists(atPath: fileURL.path)
{
print("(b) File not found")
} else
{
print("(b) File found")
}
}
catch
{
print(error.localizedDescription)
}
} else
{
print("No UbiquityContainer")
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)