I have the following code. My goal is to decode the data once the file has been downloaded to the device. I used fileExists to check if the file existed on iCloud. And then startDownloadingUbiquitousItem to download it. But I can't figure out how to tell if it has been downloaded. May I ask if there is a way to tell its downloaded? Like a completion handler or notification?
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)
}
You need to test the file NSMetadataQuery
object key NSMetadataUbiquitousItemDownloadingStatusKey
is set to NSMetadataUbiquitousItemDownloadingStatusCurrent
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.