From 579e81687398b7ba3c153240d702d907bd888715 Mon Sep 17 00:00:00 2001 From: Vlad Rusu Date: Tue, 26 Jul 2022 13:37:30 +0300 Subject: [PATCH] VSP-842 [iOS] iCloud files fail to upload sometimes - added a "Preparing files" UI - copied iCloud files locally while the "preparing" UI is on screen --- Permanent/Managers/Upload/UploadManager.swift | 6 ------ Permanent/ViewControllers/MainViewController.swift | 12 ++++++++---- Permanent/ViewModels/FilesViewModel.swift | 8 +++++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Permanent/Managers/Upload/UploadManager.swift b/Permanent/Managers/Upload/UploadManager.swift index ea5762f9..c81ac410 100644 --- a/Permanent/Managers/Upload/UploadManager.swift +++ b/Permanent/Managers/Upload/UploadManager.swift @@ -80,12 +80,6 @@ class UploadManager { if let fileContents = file.fileContents { file.url = fileHelper.saveFile(fileContents, named: file.id, withExtension: "jpeg", isDownload: false) ?? URL(fileURLWithPath: "") file.fileContents = nil - } else { - do { - file.url = try fileHelper.copyFile(withURL: file.url) - } catch { - print(error) - } } // Save file metadata diff --git a/Permanent/ViewControllers/MainViewController.swift b/Permanent/ViewControllers/MainViewController.swift index b734c204..57a90fe3 100644 --- a/Permanent/ViewControllers/MainViewController.swift +++ b/Permanent/ViewControllers/MainViewController.swift @@ -1157,12 +1157,16 @@ extension MainViewController: FilePreviewNavigationControllerDelegate { // MARK: - PhotoPickerViewControllerDelegate extension MainViewController: PhotoPickerViewControllerDelegate { func photoTabBarViewControllerDidPickAssets(_ vc: PhotoTabBarViewController?, assets: [PHAsset]) { + let alert = UIAlertController(title: "Preparing Files...".localized(), message: nil, preferredStyle: .alert) + present(alert, animated: true) viewModel?.didChooseFromPhotoLibrary(assets, completion: { [self] urls in - guard let currentFolder = viewModel?.currentFolder else { - return showErrorAlert(message: .cannotUpload) + dismiss(animated: true) { [self] in + guard let currentFolder = viewModel?.currentFolder else { + return showErrorAlert(message: .cannotUpload) + } + + processUpload(toFolder: currentFolder, forURLS: urls) } - - processUpload(toFolder: currentFolder, forURLS: urls) }) } } diff --git a/Permanent/ViewModels/FilesViewModel.swift b/Permanent/ViewModels/FilesViewModel.swift index 3a0fb466..7d6aa29e 100644 --- a/Permanent/ViewModels/FilesViewModel.swift +++ b/Permanent/ViewModels/FilesViewModel.swift @@ -360,7 +360,13 @@ class FilesViewModel: NSObject, ViewModelInterface { return } - urls.append(imageURL) + do { + let localURL = try FileHelper().copyFile(withURL: imageURL) + urls.append(localURL) + } catch { + print(error) + } + dispatchGroup.leave() } }