marinofaggiana 4 年之前
父節點
當前提交
aeaa6bd464
共有 3 個文件被更改,包括 22 次插入15 次删除
  1. 4 0
      iOSClient/AppDelegate.h
  2. 1 5
      iOSClient/AppDelegate.m
  3. 17 10
      iOSClient/Networking/NCNetworkingAutoUpload.swift

+ 4 - 0
iOSClient/AppDelegate.h

@@ -40,6 +40,7 @@
 @class NCAppConfigView;
 @class IMImagemeterViewer;
 @class NCDetailViewController;
+@class NCNetworkingAutoUpload;
 
 @interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
 
@@ -111,6 +112,9 @@
 // UserDefaults
 @property (nonatomic, strong) NSUserDefaults *ncUserDefaults;
 
+// Network Auto Upload
+@property (nonatomic, strong) NCNetworkingAutoUpload *networkingAutoUpload;
+
 // Login
 - (void)startTimerErrorNetworking;
 - (void)openLoginView:(UIViewController *)viewController selector:(NSInteger)selector openLoginWeb:(BOOL)openLoginWeb;

+ 1 - 5
iOSClient/AppDelegate.m

@@ -33,7 +33,6 @@
 @import Sentry;
 
 @class NCViewerRichdocument;
-@class NCNetworkingAutoUpload;
 
 @interface AppDelegate() <TOPasscodeViewControllerDelegate>
 @end
@@ -160,10 +159,7 @@
     });
     
     // Auto upload
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-        [NCNetworkingAutoUpload new];
-       // [NCNetworking.shared loadAutoUpload];
-    });
+    self.networkingAutoUpload = [NCNetworkingAutoUpload new];
     
     return YES;
 }

+ 17 - 10
iOSClient/Networking/NCNetworkingAutoUpload.swift

@@ -27,25 +27,35 @@ import NCCommunication
 class NCNetworkingAutoUpload: NSObject {
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var timerProcess: Timer?
     
     override init() {
         super.init()
-        process()
+
+        timerProcess = Timer.scheduledTimer(timeInterval: TimeInterval(k_timerAutoUpload), target: self, selector: #selector(process), userInfo: nil, repeats: false)
+    }
+    
+    @objc func startProcess() {
+        if timerProcess?.isValid ?? false {
+            process()
+        }
     }
 
-    @objc func process() {
+    @objc private func process() {
 
         var counterUpload = 0
         var sizeUpload = 0
         var maxConcurrentOperationUpload = k_maxConcurrentOperation
-     
+        
+        timerProcess?.invalidate()
+        
         let metadatasUpload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d", k_metadataStatusInUpload, k_metadataStatusUploading), freeze: true)
         counterUpload = metadatasUpload.count
          
         for metadata in metadatasUpload {
             sizeUpload = sizeUpload + Int(metadata.size)
         }
-         
+        
         debugPrint("[LOG] PROCESS-AUTO-UPLOAD \(counterUpload)")
     
         // ------------------------- <selector Upload> -------------------------
@@ -145,12 +155,9 @@ class NCNetworkingAutoUpload: NSObject {
         // verify delete Asset Local Identifiers in auto upload (Photos album)
         if (counterUpload == 0 && appDelegate.passcodeViewController == nil) {
             NCUtility.sharedInstance.deleteAssetLocalIdentifiers(account: appDelegate.activeAccount, sessionSelector: selectorUploadAutoUpload)
-         }
-         
-         DispatchQueue.main.asyncAfter(deadline: .now() + TimeInterval(k_timerAutoUpload)) {
-             //self.loadAutoUpload()
-         }
+        }
+        
+        timerProcess = Timer.scheduledTimer(timeInterval: TimeInterval(k_timerAutoUpload), target: self, selector: #selector(process), userInfo: nil, repeats: false)
      }
-
 }