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 - 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) {