Ios icloud驱动器文档未在设备之间即时同步
我已经使用swift实现了icloud驱动。它的代码看起来很好,就像官方文件中给出的一样,并且可以用单个设备完美地上传/下载文件。 现在,当您打算在另一台具有相同云用户的设备上下载文件时。无法在该设备中找到文件。现在,我已经从设备云设置中禁用/启用了icloud,但一段时间后,我再次尝试,其工作正常(现在在该设备上找到了文件) 因此,下面出现了一些与此相关的问题Ios icloud驱动器文档未在设备之间即时同步,ios,swift,icloud,icloud-drive,Ios,Swift,Icloud,Icloud Drive,我已经使用swift实现了icloud驱动。它的代码看起来很好,就像官方文件中给出的一样,并且可以用单个设备完美地上传/下载文件。 现在,当您打算在另一台具有相同云用户的设备上下载文件时。无法在该设备中找到文件。现在,我已经从设备云设置中禁用/启用了icloud,但一段时间后,我再次尝试,其工作正常(现在在该设备上找到了文件) 因此,下面出现了一些与此相关的问题 icloud是否不能在设备之间即时同步文件(如果不是,那么我们如何在设备之间即时同步文件) 有没有办法通知设备在云上同步新创建的文件
- icloud是否不能在设备之间即时同步文件(如果不是,那么我们如何在设备之间即时同步文件)
- 有没有办法通知设备在云上同步新创建的文件
- 当前已将文件复制到cloud.com上未列出的cloud文档。那么,我们如何在icloud上显示/隐藏复制的文件呢
if let cloudURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") {
let file = cloudURL.appendingPathComponent("file.txt")
if (FileManager.default.fileExists(atPath: file.path, isDirectory: nil)) {
do{
try FileManager.default.removeItem(at: file)
}catch let error as NSError {
print("error",error)
}
}
let localDocumentsURL = DocumentsDirectory.localDocumentsURL.appendingPathComponent("file.txt")
do {
try FileManager.default.copyItem(at: localDocumentsURL, to: file)
} catch let error as NSError{
print("can not copy file",error)
}
}
从云目录下载文件
let fileManager = FileManager.default
if let cloudURL = fileManager.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") {
let file = cloudURL.appendingPathComponent("file.txt")
do{
var downloded = false
try fileManager.startDownloadingUbiquitousItem(at: file)
while(!downloded){
if(fileManager.fileExists(atPath: file.path, isDirectory: nil)){
downloded = true
}
}
let filePath = DocumentsDirectory.localDocumentsURL.appendingPathComponent("file.txt")
try fileManager.copyItem(at: file, to: filePath)
}catch let error as NSError {
print("error",error)
}
}
您使用的是模拟器还是真实设备?在开始下载之前,您是否尝试过从第二台设备检查iCloud Documents目录中是否包含该文件?i、 e.
FileManager.default.fileExists(atPath:cloudURL.path)
我也有同样的情况,第二个设备返回false表示存在。很难找到一致性。你使用的是模拟器还是真实设备?在开始下载之前,您是否尝试过从第二台设备检查iCloud Documents目录中是否包含该文件?i、 e.FileManager.default.fileExists(atPath:cloudURL.path)
我也有同样的情况,第二个设备返回false表示存在。努力找到与此一致的地方。