Marino Faggiana 6 жил өмнө
parent
commit
eb58ab64e5

+ 18 - 3
PickerFileProvider/FileProvider.swift

@@ -48,7 +48,7 @@ var fileNamePathImport = [String]()
 var uploadMetadataNetInProgress: CCMetadataNet?
 var timerUpload: Timer?
 
-class FileProvider: NSFileProviderExtension {
+class FileProvider: NSFileProviderExtension, CCNetworkingDelegate {
     
     override init() {
         
@@ -72,12 +72,16 @@ class FileProvider: NSFileProviderExtension {
                             
                             if self.copyFile(metadataNetQueue!.path, toPath: directoryUser + "/" + metadataNetQueue!.fileName) == nil {
 
+                                CCNetworking.shared().uploadFile(metadataNetQueue!.fileName, serverUrl: metadataNetQueue!.serverUrl, assetLocalIdentifier: metadataNetQueue!.assetLocalIdentifier, session: metadataNetQueue!.session, taskStatus: metadataNetQueue!.taskStatus, selector: metadataNetQueue!.selector, selectorPost: metadataNetQueue!.selectorPost, errorCode: 0, delegate: self)
+                                /*
                                 // *** Don't capture clousure success/failure : is not affidable in extension ... problem of lib ***
                                 let task = ocNetworking?.uploadFileNameServerUrl(metadataNetQueue!.serverUrl+"/"+metadataNetQueue!.fileName, fileNameLocalPath: directoryUser + "/" + metadataNetQueue!.fileName, communication: CCNetworking.shared().sharedOCCommunicationExtensionUpload(k_upload_session_extension), success: { (fileID, etag, date) in }, failure: { (errorMessage, errorCode) in })
                                 if task != nil {
                                     uploadMetadataNetInProgress = metadataNetQueue!
                                     uploadMetadataNetInProgress!.task = task
                                 }
+                                */
+                                
                             } else {
                                 // file not present, delete record Upload Queue
                                 NCManageDatabase.sharedInstance.deleteQueueUpload(path: metadataNetQueue!.path)
@@ -85,6 +89,7 @@ class FileProvider: NSFileProviderExtension {
                         }
                     }
                     
+                    /*
                     // Verify running task
                     if uploadMetadataNetInProgress != nil && uploadMetadataNetInProgress?.task != nil {
                         let task = uploadMetadataNetInProgress!.task
@@ -153,6 +158,8 @@ class FileProvider: NSFileProviderExtension {
                         // NO running task
                         NCManageDatabase.sharedInstance.unlockAllQueueUploadInPath()
                     }
+                    */
+                    
                 })
                 RunLoop.main.add(timerUpload!, forMode: .defaultRunLoopMode)
             }
@@ -443,7 +450,7 @@ class FileProvider: NSFileProviderExtension {
             metadataNet.selector = selectorUploadFile
             metadataNet.selectorPost = ""
             metadataNet.serverUrl = serverUrl
-            metadataNet.session = k_upload_session
+            metadataNet.session = k_upload_session_extension
             metadataNet.taskStatus = Int(k_taskStatusResume)
                 
             _ = NCManageDatabase.sharedInstance.addQueueUpload(metadataNet: metadataNet)
@@ -1034,7 +1041,7 @@ class FileProvider: NSFileProviderExtension {
             metadataNet.selector = selectorUploadFile
             metadataNet.selectorPost = ""
             metadataNet.serverUrl = serverUrl
-            metadataNet.session = k_upload_session
+            metadataNet.session = k_upload_session_extension
             metadataNet.taskStatus = Int(k_taskStatusResume)
             
             _ = NCManageDatabase.sharedInstance.addQueueUpload(metadataNet: metadataNet)
@@ -1157,6 +1164,14 @@ class FileProvider: NSFileProviderExtension {
         
         return resultFileName
     }
+    
+    // --------------------------------------------------------------------------------------------
+    //  MARK: - Upload delegate
+    // --------------------------------------------------------------------------------------------
+    
+    func uploadFileSuccessFailure(_ fileName: String!, fileID: String!, assetLocalIdentifier: String!, serverUrl: String!, selector: String!, selectorPost: String!, errorMessage: String!, errorCode: Int) {
+        print("x")
+    }
 }
 
 // --------------------------------------------------------------------------------------------

+ 22 - 1
iOSClient/Networking/CCNetworking.m

@@ -167,7 +167,6 @@
         configuration.discretionary = NO;
         configuration.HTTPMaximumConnectionsPerHost = 1;
         configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
-        configuration.sharedContainerIdentifier = [NCBrandOptions sharedInstance].capabilitiesGroups;
 
         sessionUpload = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
         sessionUpload.sessionDescription = k_upload_session;
@@ -214,6 +213,27 @@
     return sessionUploadForeground;
 }
 
+- (NSURLSession *)sessionUploadExtension
+{
+    static NSURLSession *sessionUpload = nil;
+    
+    if (sessionUpload == nil) {
+        
+        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_upload_session_extension];
+        
+        configuration.allowsCellularAccess = YES;
+        configuration.sessionSendsLaunchEvents = YES;
+        configuration.discretionary = NO;
+        configuration.HTTPMaximumConnectionsPerHost = 1;
+        configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
+        configuration.sharedContainerIdentifier = [NCBrandOptions sharedInstance].capabilitiesGroups;
+        
+        sessionUpload = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
+        sessionUpload.sessionDescription = k_upload_session;
+    }
+    return sessionUpload;
+}
+
 - (OCCommunication *)sharedOCCommunication
 {
     static OCCommunication* sharedOCCommunication = nil;
@@ -1052,6 +1072,7 @@
     if ([metadata.session isEqualToString:k_upload_session]) sessionUpload = [self sessionUpload];
     else if ([metadata.session isEqualToString:k_upload_session_wwan]) sessionUpload = [self sessionWWanUpload];
     else if ([metadata.session isEqualToString:k_upload_session_foreground]) sessionUpload = [self sessionUploadForeground];
+    else if ([metadata.session isEqualToString:k_upload_session_extension]) sessionUpload = [self sessionUploadExtension];
 
     NSURLSessionUploadTask *uploadTask = [sessionUpload uploadTaskWithRequest:request fromFile:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileNameForUpload]]];