marinofaggiana 4 年之前
父節點
當前提交
9fd3600694
共有 2 個文件被更改,包括 37 次插入24 次删除
  1. 12 5
      iOSClient/AppDelegate.m
  2. 25 19
      iOSClient/Networking/NCService.swift

+ 12 - 5
iOSClient/AppDelegate.m

@@ -561,11 +561,11 @@
         return;
     }
     
-    [[NCCommunicationCommon shared] writeLog:@"Start handler refresh task"];
+    [[NCCommunicationCommon shared] writeLog:@"Start handler refresh task [Auto upload]"];
     
     [[NCAutoUpload shared] initAutoUploadWithViewController:nil completion:^(NSInteger items) {
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-            [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Completition handler refresh task with %lu uploads", (unsigned long)items]];
+            [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Completition handler refresh task with %lu uploads [Auto upload]", (unsigned long)items]];
             [task setTaskCompletedWithSuccess:true];
         });
     }];
@@ -573,10 +573,17 @@
 
 -(void)handleProcessingTask:(BGTask *)task API_AVAILABLE(ios(13.0))
 {
-    [[NCCommunicationCommon shared] writeLog:@"Start handler processing task"];
+    if (self.account == nil || self.account.length == 0) {
+        [task setTaskCompletedWithSuccess:true];
+        return;
+    }
     
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-        [[NCCommunicationCommon shared] writeLog:@"Completition handler processing task"];
+    [[NCCommunicationCommon shared] writeLog:@"Start handler processing task [Synchronize Offline]"];
+    
+    [[NCService shared] synchronizeOfflineWithAccount:self.account];
+    
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+        [[NCCommunicationCommon shared] writeLog:@"Completition handler processing task [Synchronize Offline]"];
         [task setTaskCompletedWithSuccess:true];
     });
 }

+ 25 - 19
iOSClient/Networking/NCService.swift

@@ -70,25 +70,9 @@ class NCService: NSObject {
                     // Synchronize favorite                    
                     NCNetworking.shared.listingFavoritescompletion(selector: NCBrandGlobal.shared.selectorReadFile) { (_, _, _, _) in }
                 
-                    // Synchronize Offline Directory
-                    if let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", tableAccount.account), sorted: "serverUrl", ascending: true) {
-                        for directory: tableDirectory in directories {
-                            guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(directory.ocId) else {
-                                continue
-                            }
-                            NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCBrandGlobal.shared.selectorDownloadFile)
-                        }
-                    }
-                
-                    // Synchronize Offline Files
-                    let files = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", tableAccount.account), sorted: "fileName", ascending: true)
-                    for file: tableLocalFile in files {
-                        guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(file.ocId) else {
-                            continue
-                        }
-                        NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCBrandGlobal.shared.selectorDownloadFile)
-                    }
-                             
+                    // Synchronize Offline
+                    self.synchronizeOffline(account: tableAccount.account)
+                    
                     // Get Avatar
                     let avatarUrl = "\(self.appDelegate.urlBase!)/index.php/avatar/\(self.appDelegate.user!)/\(NCBrandGlobal.shared.avatarSize)".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
                     let fileNamePath = CCUtility.getDirectoryUserData() + "/" + stringUser + "-" + self.appDelegate.user + ".png"
@@ -261,6 +245,28 @@ class NCService: NSObject {
             }
         }
     }
+    
+    @objc func synchronizeOffline(account: String) {
+        
+        // Synchronize Offline Directory
+        if let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", account), sorted: "serverUrl", ascending: true) {
+            for directory: tableDirectory in directories {
+                guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(directory.ocId) else {
+                    continue
+                }
+                NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCBrandGlobal.shared.selectorDownloadFile)
+            }
+        }
+    
+        // Synchronize Offline Files
+        let files = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", account), sorted: "fileName", ascending: true)
+        for file: tableLocalFile in files {
+            guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(file.ocId) else {
+                continue
+            }
+            NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCBrandGlobal.shared.selectorDownloadFile)
+        }
+    }
    
     //MARK: - Thirt Part