如何解决将文件写入iCloud-文件不显示
我一直在浪费很多时间来解决这个问题。我正在尝试将文件写入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 举报,一经查实,本站将立刻删除。