Document saved on iCloud Drive seems not to be downloaded on iOS

南笙酒味 提交于 2021-02-18 18:14:34

问题


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.

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?

Using Swift 2 on iOS 8/9.


回答1:


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
}


来源:https://stackoverflow.com/questions/33462352/document-saved-on-icloud-drive-seems-not-to-be-downloaded-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!