【发布时间】:2020-09-21 19:04:53
【问题描述】:
我有以下代码。我的目标是在文件下载到设备后解码数据。我使用 fileExists 来检查文件是否存在于 iCloud 上。然后 startDownloadingUbiquitousItem 下载它。但我不知道如何判断它是否已下载。请问有没有办法告诉它下载了?像完成处理程序或通知?
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)
}
【问题讨论】:
-
你需要设置一个观察者通知。看这里; stackoverflow.com/questions/51843828/…
标签: ios swift icloud cloudkit nsfilemanager