marinofaggiana 4 rokov pred
rodič
commit
f58dd81328

+ 2 - 2
iOSClient/CCGlobal.h

@@ -334,9 +334,9 @@
 #define k_notificationCenter_reloadDataNCShare          @"reloadDataNCShare"
 #define k_notificationCenter_reloadDataNotification     @"reloadDataNotification"
 
-#define k_notificationCenter_uploadFileStart            @"uploadFileStart"                  // userInfo: ocId, uploadTask, serverUrl, account
+#define k_notificationCenter_uploadFileStart            @"uploadFileStart"                  // userInfo: ocId, task, serverUrl, account
 #define k_notificationCenter_uploadedFile               @"uploadedFile"                     // userInfo: metadata, errorCode, errorDescription
-#define k_notificationCenter_downloadFileStart          @"downloadFileStart"                // userInfo: ocId, uploadTask, serverUrl, account
+#define k_notificationCenter_downloadFileStart          @"downloadFileStart"                // userInfo: ocId, task, serverUrl, account
 #define k_notificationCenter_downloadedFile             @"downloadedFile"                   // userInfo: metadata, errorCode, errorDescription
 #define k_notificationCenter_progressTask               @"progressTask"
 

+ 0 - 4
iOSClient/Main/NCMainCommon.swift

@@ -1127,10 +1127,6 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate, IMImagemeterViewerDelega
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
 
     // DOWNLOAD
-    func downloadStart(_ ocId: String!, account: String!, task: URLSessionDownloadTask!, serverUrl: String!) {
-        NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
-        appDelegate.updateApplicationIconBadgeNumber()
-    }
     
     func downloadFileSuccessFailure(_ fileName: String!, ocId: String!, serverUrl: String!, selector: String!, errorMessage: String!, errorCode: Int) {
         

+ 0 - 1
iOSClient/Networking/CCNetworking.h

@@ -59,7 +59,6 @@
 
 #pragma mark ===== Download delegate =====
 
-@optional - (void)downloadStart:(NSString *)ocId account:(NSString *)account task:(NSURLSessionDownloadTask *)task serverUrl:(NSString *)serverUrl;
 @optional  - (void)downloadFileSuccessFailure:(NSString *)fileName ocId:(NSString *)ocId serverUrl:(NSString *)serverUrl selector:(NSString *)selector errorMessage:(NSString *)errorMessage errorCode:(NSInteger)errorCode;
 
 @end

+ 3 - 7
iOSClient/Networking/CCNetworking.m

@@ -441,11 +441,7 @@
         
         NSLog(@"[LOG] downloadFileSession %@ Task [%lu]", metadata.ocId, (unsigned long)downloadTask.taskIdentifier);
         
-        dispatch_async(dispatch_get_main_queue(), ^{
-            if ([self.delegate respondsToSelector:@selector(downloadStart:account:task:serverUrl:)]) {
-                [self.delegate downloadStart:metadata.ocId account:metadata.account task:downloadTask serverUrl:metadata.serverUrl];
-            }
-        });
+        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_downloadFileStart object:nil userInfo:@{@"ocId": metadata.ocId, @"task": downloadTask, @"serverUrl": metadata.serverUrl, @"account": metadata.account}];
     }
 }
 
@@ -953,7 +949,7 @@
                         NSString *account = metadata.account;
                                                     
                         // NSNotificationCenter
-                        NSDictionary* userInfo = @{@"ocId": ocId, @"uploadTask": uploadTask, @"serverUrl": serverUrl, @"account": account};
+                        NSDictionary* userInfo = @{@"ocId": ocId, @"task": uploadTask, @"serverUrl": serverUrl, @"account": account};
                         [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadFileStart object:nil userInfo:userInfo];
                     }
                 });
@@ -976,7 +972,7 @@
              NSString *serverUrl = metadata.serverUrl;
                               
             // NSNotificationCenter
-            NSDictionary* userInfo = @{@"ocId": ocId, @"uploadTask": uploadTask, @"serverUrl": serverUrl, @"account": account};
+            NSDictionary* userInfo = @{@"ocId": ocId, @"task": uploadTask, @"serverUrl": serverUrl, @"account": account};
             [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadFileStart object:nil userInfo:userInfo];
          }
     }

+ 16 - 1
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -27,6 +27,8 @@ import Foundation
     @objc public static let shared: NCNetworkingNotificationCenter = {
         let instance = NCNetworkingNotificationCenter()
         
+        NotificationCenter.default.addObserver(instance, selector: #selector(downloadFileStart(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_downloadFileStart), object: nil)
+        
         NotificationCenter.default.addObserver(instance, selector: #selector(uploadFileStart(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_uploadFileStart), object: nil)
         NotificationCenter.default.addObserver(instance, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_uploadedFile), object: nil)
         
@@ -35,12 +37,25 @@ import Foundation
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     
+    //MARK: - Download
+
+    @objc func downloadFileStart(_ notification: NSNotification) {
+        
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let ocId = userInfo["ocId"] as? String, let serverUrl = userInfo["serverUrl"] as? String, let _ = userInfo["task"] as? URLSessionDownloadTask {
+                
+                NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
+                appDelegate.updateApplicationIconBadgeNumber()
+            }
+        }
+    }
+    
     //MARK: - Upload
 
     @objc func uploadFileStart(_ notification: NSNotification) {
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let serverUrl = userInfo["serverUrl"] as? String, let _ = userInfo["uploadTask"] as? URLSessionUploadTask {
+            if let ocId = userInfo["ocId"] as? String, let serverUrl = userInfo["serverUrl"] as? String, let _ = userInfo["task"] as? URLSessionUploadTask {
                 
                 NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
                 appDelegate.updateApplicationIconBadgeNumber()