From 9d05ccece8f607e0a91a4da7352c4fe1926c214d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20St=C3=A4rk?= Date: Thu, 16 Nov 2023 11:05:31 +0100 Subject: [PATCH 1/2] prevent "No Space Left on Device" error when hundreds of request are made --- src/ios/AFNetworking/AFURLSessionManager.m | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ios/AFNetworking/AFURLSessionManager.m b/src/ios/AFNetworking/AFURLSessionManager.m index 8cecdb8a..f515cba0 100644 --- a/src/ios/AFNetworking/AFURLSessionManager.m +++ b/src/ios/AFNetworking/AFURLSessionManager.m @@ -716,13 +716,11 @@ - (NSArray *)downloadTasks { #pragma mark - - (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks { - dispatch_async(dispatch_get_main_queue(), ^{ - if (cancelPendingTasks) { - [self.session invalidateAndCancel]; - } else { - [self.session finishTasksAndInvalidate]; - } - }); + if (cancelPendingTasks) { + [self.session invalidateAndCancel]; + } else { + [self.session finishTasksAndInvalidate]; + } } #pragma mark - From 0399294f5ef05200319419d2dc25ab5fc2f696a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20St=C3=A4rk?= Date: Thu, 16 Nov 2023 15:32:43 +0100 Subject: [PATCH 2/2] [iOS] invalidate session on upload and download success and failure --- src/ios/CordovaHttpPlugin.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ios/CordovaHttpPlugin.m b/src/ios/CordovaHttpPlugin.m index cfcb8f6d..032daaab 100644 --- a/src/ios/CordovaHttpPlugin.m +++ b/src/ios/CordovaHttpPlugin.m @@ -462,6 +462,7 @@ - (void)uploadFiles:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity]; + [manager invalidateSessionCancelingTasks:YES]; } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error]; @@ -469,6 +470,7 @@ - (void)uploadFiles:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity]; + [manager invalidateSessionCancelingTasks:YES]; }]; } @catch (NSException *exception) { @@ -539,6 +541,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity]; + [manager invalidateSessionCancelingTasks:YES]; return; } NSData *data = (NSData *)responseObject; @@ -549,6 +552,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity]; + [manager invalidateSessionCancelingTasks:YES]; return; } @@ -560,6 +564,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity]; + [manager invalidateSessionCancelingTasks:YES]; } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error]; @@ -568,6 +573,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity]; + [manager invalidateSessionCancelingTasks:YES]; }]; } @catch (NSException *exception) {