如何判断iCloud文件是否已下载?

时间:2020-06-03 06:46:40

标签: ios swift icloud cloudkit nsfilemanager

我有以下代码。我的目标是在文件下载到设备后对数据进行解码。我使用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)
            }

1 个答案:

答案 0 :(得分:0)

您需要测试文件NSMetadataQuery对象密钥NSMetadataUbiquitousItemDownloadingStatusKey设置为NSMetadataUbiquitousItemDownloadingStatusCurrent

相关问题