【问题标题】:Document saved on iCloud Drive seems not to be downloaded on iOS保存在 iCloud Drive 上的文档似乎无法在 iOS 上下载
【发布时间】:2016-02-01 10:26:43
【问题描述】:

我会让用户使用 iCloud 驱动器保存他的数据备份。效果很好。但如果我切换到另一个支持 iCloud Drive 的设备,我就无法读取该文件。

我可以在 iCloud Drive 应用程序中看到备份文件,但它没有下载,(它显示“从 icloud 下载符号)。

如果用户想要恢复备份,是否可以强制下载目录中的所有可用文件?

在 iOS 8/9 上使用 Swift 2。

【问题讨论】:

    标签: ios swift icloud icloud-drive


    【解决方案1】:

    我自己解决了这个问题。 我会检查我的备份文件是否可用以及是否需要下载。如果是这样,我将开始下载并通知用户几秒钟后再回来查看。不是最好的解决方案,但现在可以了。

    func checkAndDownloadBackupFile() -> Bool{
        if(iCloudDocumentsURL != nil){
            let file = iCloudDocumentsURL!.URLByAppendingPathComponent("backup.file")
            let filemanager = NSFileManager.defaultManager();
    
            if !filemanager.fileExistsAtPath(file.path!){
    
                if filemanager.isUbiquitousItemAtURL(file) {
                    let alertView:UIAlertView = UIAlertView()
                    alertView.title =  "Warning"
                    alertView.message = "iCloud is currently busy syncing the backup files. Please try again in a few minutes."
                    alertView.addButtonWithTitle("OK")
                    alertView.show()
    
                    do {
                        try filemanager.startDownloadingUbiquitousItemAtURL(file)
                    } catch{
                        print("Error while loading Backup File \(error)")
                    }
                }
                return false
            } else{
                return true
            }
        }
        return true
    }
    

    【讨论】:

    • 根据文档 isUbiquitousItemAtURL 不是获取下载状态的方法。 “这种方法并不能反映文件是否真的已经上传到任何 iCloud 服务器。”
    • 但它似乎表明文件/文件夹是否是 iCloud 文件/文件夹。
    • 这项技术对我有用——文件夹。在我的情况下,显示文件夹名称,但不显示它们的内容。在每个 iCloud Drive 文件夹上使用 startDownloadingUbiquitousItem 会触发下载。
    • 是否有任何最佳实践来处理这种情况?我尝试在 iCloud 中的特定文件夹中强制 startDownloadingUbiquitousItemAtURL,但这对我不起作用。仅当您知道文件名时才有效..
    猜你喜欢
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 2016-02-16
    • 2018-02-01
    • 2016-12-22
    • 1970-01-01
    • 2016-01-12
    • 2021-03-04
    相关资源
    最近更新 更多