问题
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