保存在iCloud Drive上的文档似乎无法在iOS上下载 [英] Document saved on iCloud Drive seems not to be downloaded on iOS

查看:176
本文介绍了保存在iCloud Drive上的文档似乎无法在iOS上下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将让用户使用iCloud驱动器保存其数据的备份.很好但是,如果我切换到另一台启用了iCloud Drive的设备,则无法读取该文件.

I'll let the user save backup of his data using iCloud drive. That works good. But if I switch to another iCloud Drive enabled device, I can't read the file.

我可以在iCloud Drive App中看到备份文件,但尚未下载(显示从icloud符号下载").

I can see the backup file within the iCloud Drive App, but it's not downloaded, (it shows the "download from icloud symbol).

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

Is it possible to force the download of all files available within the directory if the user wants to restore a backup?

在iOS 8/9上使用Swift 2.

Using Swift 2 on iOS 8/9.

推荐答案

我自己解决了这个问题.我将检查我的备份文件是否可用以及是否需要下载.如果是这样,我将开始下载并通知用户几秒钟后再检查一次.这不是最好的解决方案,但目前可以使用.

I've solved this by myself. I'll check whether my backup file is available and if it needs to be downloaded. If so, I'll start the download and inform the user to check back in a few seconds. Not the best solution, but for now it works.

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
}

这篇关于保存在iCloud Drive上的文档似乎无法在iOS上下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆