Skip to content

Commit 37e96b2

Browse files
authored
Merge pull request #3 from ns0m/ios-performance-improvements
[iOS] prevent "No Space Left on Device" error when hundreds of request are made
2 parents cdf819a + 0399294 commit 37e96b2

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/ios/AFNetworking/AFURLSessionManager.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -716,13 +716,11 @@ - (NSArray *)downloadTasks {
716716
#pragma mark -
717717

718718
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks {
719-
dispatch_async(dispatch_get_main_queue(), ^{
720-
if (cancelPendingTasks) {
721-
[self.session invalidateAndCancel];
722-
} else {
723-
[self.session finishTasksAndInvalidate];
724-
}
725-
});
719+
if (cancelPendingTasks) {
720+
[self.session invalidateAndCancel];
721+
} else {
722+
[self.session finishTasksAndInvalidate];
723+
}
726724
}
727725

728726
#pragma mark -

src/ios/CordovaHttpPlugin.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,15 @@ - (void)uploadFiles:(CDVInvokedUrlCommand*)command {
462462
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
463463
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
464464
[[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity];
465+
[manager invalidateSessionCancelingTasks:YES];
465466
} failure:^(NSURLSessionTask *task, NSError *error) {
466467
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
467468
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
468469

469470
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
470471
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
471472
[[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity];
473+
[manager invalidateSessionCancelingTasks:YES];
472474
}];
473475
}
474476
@catch (NSException *exception) {
@@ -539,6 +541,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
539541
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
540542
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
541543
[[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity];
544+
[manager invalidateSessionCancelingTasks:YES];
542545
return;
543546
}
544547
NSData *data = (NSData *)responseObject;
@@ -549,6 +552,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
549552
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
550553
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
551554
[[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity];
555+
[manager invalidateSessionCancelingTasks:YES];
552556
return;
553557
}
554558

@@ -560,6 +564,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
560564
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
561565
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
562566
[[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity];
567+
[manager invalidateSessionCancelingTasks:YES];
563568
} failure:^(NSURLSessionTask *task, NSError *error) {
564569
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
565570
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
@@ -568,6 +573,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
568573
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
569574
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
570575
[[SDNetworkActivityIndicator sharedActivityIndicator] stopActivity];
576+
[manager invalidateSessionCancelingTasks:YES];
571577
}];
572578
}
573579
@catch (NSException *exception) {

0 commit comments

Comments
 (0)