我有以下代码。我的目标是在文件下载到设备后对数据进行解码。我使用fileExists来检查文件是否存在于iCloud上。然后开始DownloadingUbiquitousItem进行下载。但我不知道如何判断它是否已下载。请问有没有办法告诉它下载了?像完成处理程序或通知一样?
if paperyCloudURL != nil, FileManager.default.fileExists(atPath: paperyCloudURL!.path, isDirectory: nil) {
try? FileManager.default.startDownloadingUbiquitousItem(at: paperyCloudURL!)
//TODO: Should have check if the file exist before load
let data = try Data(contentsOf: paperyCloudURL!)
dataModel = try! decoder.decode(DataModel.self, from: data)
}
答案 0 :(得分:0)
您需要测试文件NSMetadataQuery
对象密钥NSMetadataUbiquitousItemDownloadingStatusKey
设置为NSMetadataUbiquitousItemDownloadingStatusCurrent
。