【问题标题】:How to tell if iCloud file has been downloaded?如何判断 iCloud 文件是否已下载?
【发布时间】: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)
            }

【问题讨论】:

标签: ios swift icloud cloudkit nsfilemanager


【解决方案1】:

你需要测试文件NSMetadataQuery对象键NSMetadataUbiquitousItemDownloadingStatusKey是否设置为NSMetadataUbiquitousItemDownloadingStatusCurrent

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    相关资源
    最近更新 更多