Marino Faggiana 7 years ago
parent
commit
a51f07634b

+ 6 - 6
PickerFileProvider/FileProvider.swift

@@ -282,7 +282,7 @@ class FileProvider: NSFileProviderExtension {
                     return
                 }
                 
-                _ = ocNetworking?.downloadFileNameServerUrl("\(directory.serverUrl)/\(metadata.fileName)", fileNameLocalPath: "\(directoryUser)/\(metadata.fileID)", communication: CCNetworking.shared().sharedOCCommunicationExtension(), success: { (lenght) in
+                _ = ocNetworking?.downloadFileNameServerUrl("\(directory.serverUrl)/\(metadata.fileName)", fileNameLocalPath: "\(directoryUser)/\(metadata.fileID)", communication: CCNetworking.shared().sharedOCCommunicationExtensionDownload(metadata.fileName), success: { (lenght) in
                     
                     if (lenght > 0) {
                         
@@ -361,7 +361,7 @@ class FileProvider: NSFileProviderExtension {
                     uploading.append(serverUrl+"/"+fileName)
                 }
                 
-                _ =  ocNetworking?.uploadFileNameServerUrl(serverUrl+"/"+fileName, fileNameLocalPath: url.path, communication: CCNetworking.shared().sharedOCCommunicationExtension(), success: { (fileID, etag, date) in
+                _ =  ocNetworking?.uploadFileNameServerUrl(serverUrl+"/"+fileName, fileNameLocalPath: url.path, communication: CCNetworking.shared().sharedOCCommunicationExtensionUpload(fileName), success: { (fileID, etag, date) in
                     
                     let toPath = "\(directoryUser)/\(metadata.fileID)"
 
@@ -536,7 +536,7 @@ class FileProvider: NSFileProviderExtension {
                     let fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: serverUrl, activeUrl: accountUrl)
                     let fileNameLocal = metadata.fileID
 
-                    ocNetworking?.downloadThumbnail(withDimOfThumbnail: "m", fileName: fileName, fileNameLocal: fileNameLocal, communication: CCNetworking.shared().sharedOCCommunicationExtension(), success: {
+                    ocNetworking?.downloadThumbnail(withDimOfThumbnail: "m", fileName: fileName, fileNameLocal: fileNameLocal, success: {
 
                         do {
                             let url = URL.init(fileURLWithPath: "\(directoryUser)/\(item.rawValue).ico")
@@ -605,7 +605,7 @@ class FileProvider: NSFileProviderExtension {
             serverUrl = directoryParent.serverUrl
         }
         
-        ocNetworking?.createFolder(directoryName, serverUrl: serverUrl, account: account, communication: CCNetworking.shared().sharedOCCommunicationExtension(), success: { (fileID, date) in
+        ocNetworking?.createFolder(directoryName, serverUrl: serverUrl, account: account, success: { (fileID, date) in
                 
             guard let newTableDirectory = NCManageDatabase.sharedInstance.addDirectory(encrypted: false, favorite: false, fileID: fileID, permissions: nil, serverUrl: serverUrl+"/"+directoryName) else {
                 completionHandler(nil, NSFileProviderError(.noSuchItem))
@@ -648,7 +648,7 @@ class FileProvider: NSFileProviderExtension {
             return
         }
         
-        ocNetworking?.deleteFileOrFolder(metadata.fileName, serverUrl: serverUrl, communication: CCNetworking.shared().sharedOCCommunicationExtension(), success: {
+        ocNetworking?.deleteFileOrFolder(metadata.fileName, serverUrl: serverUrl, success: {
             
             let fileNamePath = directoryUser + "/" + metadata.fileID
             do {
@@ -791,7 +791,7 @@ class FileProvider: NSFileProviderExtension {
         
        
         // upload
-        _ = ocNetworking?.uploadFileNameServerUrl(serverUrl+"/"+fileName, fileNameLocalPath: fileNameLocalPath.path, communication: CCNetworking.shared().sharedOCCommunicationExtension(), success: { (fileID, etag, date) in
+        _ = ocNetworking?.uploadFileNameServerUrl(serverUrl+"/"+fileName, fileNameLocalPath: fileNameLocalPath.path, communication: CCNetworking.shared().sharedOCCommunicationExtensionUpload(fileName), success: { (fileID, etag, date) in
                 
             let metadata = tableMetadata()
                 

+ 1 - 1
PickerFileProvider/FileProviderEnumerator.swift

@@ -91,7 +91,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
             }
             
             // Read Folder
-            ocNetworking?.readFolder(withServerUrl: serverUrl, depth: "1", account: account, communication: CCNetworking.shared().sharedOCCommunicationExtension(),success: { (metadatas, metadataFolder, directoryID) in
+            ocNetworking?.readFolder(withServerUrl: serverUrl, depth: "1", account: account, success: { (metadatas, metadataFolder, directoryID) in
                 
                 if (metadatas != nil) {
                     NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "account = %@ AND directoryID = %@ AND session = ''", account, directoryID!), clearDateReadDirectoryID: directoryID!)

+ 3 - 1
iOSClient/Networking/CCNetworking.h

@@ -49,7 +49,9 @@
 
 // Sessions - Task
 - (OCCommunication *)sharedOCCommunication;
-- (OCCommunication *)sharedOCCommunicationExtension;
+- (OCCommunication *)sharedOCCommunicationExtensionDownload:(NSString *)identifier;
+- (OCCommunication *)sharedOCCommunicationExtensionUpload:(NSString *)identifier;
+
 - (NSURLSession *)getSessionfromSessionDescription:(NSString *)sessionDescription;
 
 - (void)invalidateAndCancelAllSession;

+ 44 - 39
iOSClient/Networking/CCNetworking.m

@@ -264,59 +264,64 @@
     return sharedOCCommunication;
 }
 
-- (OCCommunication *)sharedOCCommunicationExtension
+- (OCCommunication *)sharedOCCommunicationExtensionDownload:(NSString *)identifier
 {
-    static OCCommunication* sharedOCCommunicationExtension = nil;
+    static OCCommunication *sharedOCCommunicationExtensionDownload = nil;
+    static NSString *extensionDownloadIdentifier = @"com.nextcloud.download.session.extension";
     
-    if (sharedOCCommunicationExtension == nil)
+    if (sharedOCCommunicationExtensionDownload == nil || [extensionDownloadIdentifier isEqualToString:identifier] == false)
     {
-        // Network
-        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-        configuration.allowsCellularAccess = YES;
-        configuration.discretionary = NO;
-        configuration.HTTPMaximumConnectionsPerHost = k_maxConcurrentOperation;
-        configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
-        
-        OCURLSessionManager *networkSessionManager = [[OCURLSessionManager alloc] initWithSessionConfiguration:configuration];
-        [networkSessionManager.operationQueue setMaxConcurrentOperationCount: k_maxConcurrentOperation];
-        networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
-        
         // Download
-        NSURLSessionConfiguration *configurationDownload = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"x"];
-        configurationDownload.sharedContainerIdentifier = [NCBrandOptions sharedInstance].capabilitiesGroups;
-        configurationDownload.HTTPMaximumConnectionsPerHost = 1;
-        configurationDownload.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
-        configurationDownload.timeoutIntervalForRequest = k_timeout_upload;
-        configurationDownload.sessionSendsLaunchEvents = YES;
-        [configurationDownload setAllowsCellularAccess:YES];
-        
-        OCURLSessionManager *downloadSessionManager = [[OCURLSessionManager alloc] initWithSessionConfiguration:configurationDownload];
-        [downloadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
-        [downloadSessionManager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
+        NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier];
+        config.sharedContainerIdentifier = [NCBrandOptions sharedInstance].capabilitiesGroups;
+        config.HTTPMaximumConnectionsPerHost = 1;
+        config.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
+        config.timeoutIntervalForRequest = k_timeout_upload;
+        config.sessionSendsLaunchEvents = YES;
+        [config setAllowsCellularAccess:YES];
+        
+        OCURLSessionManager *sessionManager = [[OCURLSessionManager alloc] initWithSessionConfiguration:config];
+        [sessionManager.operationQueue setMaxConcurrentOperationCount:1];
+        [sessionManager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
             return NSURLSessionAuthChallengePerformDefaultHandling;
         }];
         
-        // Upload
-        NSURLSessionConfiguration *configurationUpload = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"xx"];;
-        configurationUpload.sharedContainerIdentifier = [NCBrandOptions sharedInstance].capabilitiesGroups;
-        configurationUpload.HTTPMaximumConnectionsPerHost = 1;
-        configurationUpload.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
-        configurationUpload.timeoutIntervalForRequest = k_timeout_upload;
-        configurationUpload.allowsCellularAccess = YES;
-        
-        OCURLSessionManager *uploadSessionManager = [[OCURLSessionManager alloc] initWithSessionConfiguration:configurationUpload];
-        [uploadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
-        [uploadSessionManager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
+        extensionDownloadIdentifier = identifier;
+        sharedOCCommunicationExtensionDownload = [[OCCommunication alloc] initWithUploadSessionManager:nil andDownloadSessionManager:sessionManager andNetworkSessionManager:nil];
+    }
+    
+    return sharedOCCommunicationExtensionDownload;
+}
+
+- (OCCommunication *)sharedOCCommunicationExtensionUpload:(NSString *)identifier
+{
+    static OCCommunication *sharedOCCommunicationExtensionDownload = nil;
+    static NSString *extensionDownloadIdentifier = @"com.nextcloud.upload.session.extension";
+    
+    if (sharedOCCommunicationExtensionDownload == nil || [extensionDownloadIdentifier isEqualToString:identifier] == false)
+    {
+        // Download
+        NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier];
+        config.sharedContainerIdentifier = [NCBrandOptions sharedInstance].capabilitiesGroups;
+        config.HTTPMaximumConnectionsPerHost = 1;
+        config.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
+        config.timeoutIntervalForRequest = k_timeout_upload;
+        config.sessionSendsLaunchEvents = YES;
+        [config setAllowsCellularAccess:YES];
+        
+        OCURLSessionManager *sessionManager = [[OCURLSessionManager alloc] initWithSessionConfiguration:config];
+        [sessionManager.operationQueue setMaxConcurrentOperationCount:1];
+        [sessionManager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
             return NSURLSessionAuthChallengePerformDefaultHandling;
         }];
         
-        sharedOCCommunicationExtension = [[OCCommunication alloc] initWithUploadSessionManager:uploadSessionManager andDownloadSessionManager:downloadSessionManager andNetworkSessionManager:networkSessionManager];
+        extensionDownloadIdentifier = identifier;
+        sharedOCCommunicationExtensionDownload = [[OCCommunication alloc] initWithUploadSessionManager:sessionManager andDownloadSessionManager:nil andNetworkSessionManager:nil];
     }
     
-    return sharedOCCommunicationExtension;
+    return sharedOCCommunicationExtensionDownload;
 }
 
-
 - (NSURLSession *)getSessionfromSessionDescription:(NSString *)sessionDescription
 {
     if ([sessionDescription isEqualToString:k_download_session]) return [self sessionDownload];

+ 4 - 4
iOSClient/Networking/OCNetworking.h

@@ -44,10 +44,10 @@
 
 - (NSURLSessionTask *)downloadFileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication success:(void (^)(int64_t length))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (NSURLSessionTask *)uploadFileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication success:(void(^)(NSString *fileID, NSString *etag, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
-- (void)downloadThumbnailWithDimOfThumbnail:(NSString *)dimOfThumbnail fileName:(NSString *)fileName fileNameLocal:(NSString *)fileNameLocal communication:(OCCommunication *)communication success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
-- (void)readFolderWithServerUrl:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account communication:(OCCommunication *)communication success:(void(^)(NSArray *metadatas, tableMetadata *metadataFolder, NSString *directoryID))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
-- (void)deleteFileOrFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl communication:(OCCommunication *)communication success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
-- (void)createFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account communication:(OCCommunication *)communication success:(void(^)(NSString *fileID, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
+- (void)downloadThumbnailWithDimOfThumbnail:(NSString *)dimOfThumbnail fileName:(NSString *)fileName fileNameLocal:(NSString *)fileNameLocal success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
+- (void)readFolderWithServerUrl:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account success:(void(^)(NSArray *metadatas, tableMetadata *metadataFolder, NSString *directoryID))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
+- (void)deleteFileOrFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
+- (void)createFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account success:(void(^)(NSString *fileID, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 
 @end
 

+ 13 - 5
iOSClient/Networking/OCNetworking.m

@@ -290,8 +290,10 @@
     }];
 }
 
-- (void)downloadThumbnailWithDimOfThumbnail:(NSString *)dimOfThumbnail fileName:(NSString *)fileName fileNameLocal:(NSString *)fileNameLocal communication:(OCCommunication *)communication success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+- (void)downloadThumbnailWithDimOfThumbnail:(NSString *)dimOfThumbnail fileName:(NSString *)fileName fileNameLocal:(NSString *)fileNameLocal success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
 {
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+
     __block NSString *ext;
     NSInteger width = 0, height = 0;
     
@@ -396,8 +398,10 @@
     }];
 }
 
-- (void)readFolderWithServerUrl:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account communication:(OCCommunication *)communication success:(void(^)(NSArray *metadatas, tableMetadata *metadataFolder, NSString *directoryID))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+- (void)readFolderWithServerUrl:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account success:(void(^)(NSArray *metadatas, tableMetadata *metadataFolder, NSString *directoryID))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
 {
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
@@ -921,10 +925,12 @@
     }];
 }
 
-- (void)createFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account communication:(OCCommunication *)communication success:(void(^)(NSString *fileID, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
-{    
+- (void)createFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account success:(void(^)(NSString *fileID, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+{
     NSString *serverFileUrl = [NSString stringWithFormat:@"%@/%@", serverUrl, fileName];
     
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
@@ -1004,10 +1010,12 @@
     }];
 }
 
-- (void)deleteFileOrFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl communication:(OCCommunication *)communication success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+- (void)deleteFileOrFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
 {    
     NSString *serverFileUrl = [NSString stringWithFormat:@"%@/%@", serverUrl, fileName];
     
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];