marinofaggiana 4 years ago
parent
commit
4288f762b2

+ 7 - 3
iOSClient/Networking/NCNetworkingAutoUpload.swift

@@ -150,10 +150,14 @@ class NCNetworkingAutoUpload: NSObject {
          
         // verify delete Asset Local Identifiers in auto upload (DELETE Photos album)
         if (counterUpload == 0 && appDelegate.passcodeViewController == nil) {
-            NCUtility.sharedInstance.deleteAssetLocalIdentifiers(account: appDelegate.activeAccount, sessionSelector: selectorUploadAutoUpload)
+            NCUtility.sharedInstance.deleteAssetLocalIdentifiers(account: appDelegate.activeAccount, sessionSelector: selectorUploadAutoUpload) {
+                
+                self.timerProcess = Timer.scheduledTimer(timeInterval: TimeInterval(k_timerAutoUpload), target: self, selector: #selector(self.process), userInfo: nil, repeats: true)
+            }
+        } else {
+            
+            timerProcess = Timer.scheduledTimer(timeInterval: TimeInterval(k_timerAutoUpload), target: self, selector: #selector(process), userInfo: nil, repeats: true)
         }
-        
-        timerProcess = Timer.scheduledTimer(timeInterval: TimeInterval(k_timerAutoUpload), target: self, selector: #selector(process), userInfo: nil, repeats: true)
      }
 }
 

+ 14 - 4
iOSClient/Utility/NCUtility.swift

@@ -532,13 +532,22 @@ class NCUtility: NSObject {
     }
     
     // Delete Asset on Photos album
-    @objc func deleteAssetLocalIdentifiers(account: String, sessionSelector: String) {
+    @objc func deleteAssetLocalIdentifiers(account: String, sessionSelector: String, completition: @escaping () -> ()) {
         
-        if UIApplication.shared.applicationState != .active { return }
+        if UIApplication.shared.applicationState != .active {
+            completition()
+            return
+        }
         let metadatasSessionUpload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND session CONTAINS[cd] %@", account, "upload"))
-        if metadatasSessionUpload.count > 0 { return }
+        if metadatasSessionUpload.count > 0 {
+            completition()
+            return
+        }
         let localIdentifiers = NCManageDatabase.sharedInstance.getAssetLocalIdentifiersUploaded(account: account, sessionSelector: sessionSelector)
-        if localIdentifiers.count == 0 { return }
+        if localIdentifiers.count == 0 {
+            completition()
+            return
+        }
         let assets = PHAsset.fetchAssets(withLocalIdentifiers: localIdentifiers, options: nil)
         
         PHPhotoLibrary.shared().performChanges({
@@ -546,6 +555,7 @@ class NCUtility: NSObject {
         }, completionHandler: { success, error in
             DispatchQueue.main.async {
                 NCManageDatabase.sharedInstance.clearAssetLocalIdentifiers(localIdentifiers, account: account)
+                completition()
             }
         })
     }