瀏覽代碼

fix code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 年之前
父節點
當前提交
d7471ca3ec
共有 1 個文件被更改,包括 11 次插入6 次删除
  1. 11 6
      iOSClient/Networking/NCNetworkingProcessUpload.swift

+ 11 - 6
iOSClient/Networking/NCNetworkingProcessUpload.swift

@@ -90,6 +90,8 @@ class NCNetworkingProcessUpload: NSObject {
 
         if appDelegate.account.isEmpty || pauseProcess {
             return completition(0)
+        } else {
+            pauseProcess = true
         }
 
         let applicationState = UIApplication.shared.applicationState
@@ -179,7 +181,11 @@ class NCNetworkingProcessUpload: NSObject {
 
                     // verify delete Asset Local Identifiers in auto upload (DELETE Photos album)
                     if applicationState == .active && metadatas.isEmpty && !self.appDelegate.isPasscodePresented() {
-                        self.deleteAssetLocalIdentifiers()
+                        self.deleteAssetLocalIdentifiers {
+                            self.pauseProcess = false
+                        }
+                    } else {
+                        self.pauseProcess = false
                     }
                 }
 
@@ -188,22 +194,21 @@ class NCNetworkingProcessUpload: NSObject {
         }
     }
 
-    private func deleteAssetLocalIdentifiers() {
+    private func deleteAssetLocalIdentifiers(completition: @escaping () -> Void) {
 
         let metadatasSessionUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND session CONTAINS[cd] %@", appDelegate.account, "upload"))
-        if !metadatasSessionUpload.isEmpty { return }
+        if !metadatasSessionUpload.isEmpty { return completition() }
 
         let localIdentifiers = NCManageDatabase.shared.getAssetLocalIdentifiersUploaded(account: appDelegate.account)
-        if localIdentifiers.isEmpty { return }
+        if localIdentifiers.isEmpty { return completition() }
 
         let assets = PHAsset.fetchAssets(withLocalIdentifiers: localIdentifiers, options: nil)
-        self.pauseProcess = true
 
         PHPhotoLibrary.shared().performChanges({
             PHAssetChangeRequest.deleteAssets(assets as NSFastEnumeration)
         }, completionHandler: { _, _ in
             NCManageDatabase.shared.clearAssetLocalIdentifiers(localIdentifiers, account: self.appDelegate.account)
-            self.pauseProcess = false
+            completition()
         })
     }