From 394aa99cbdb28cff393506bfa044b8e2480826f9 Mon Sep 17 00:00:00 2001 From: Morgan Laupies Date: Wed, 7 Feb 2018 14:07:45 +0100 Subject: [PATCH] fix call api on background thread --- ios/RNFetchBlobNetwork.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ios/RNFetchBlobNetwork.m b/ios/RNFetchBlobNetwork.m index 7be57fc59..3429f5732 100644 --- a/ios/RNFetchBlobNetwork.m +++ b/ios/RNFetchBlobNetwork.m @@ -169,7 +169,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options self.expectedBytes = 0; self.receivedBytes = 0; self.options = options; - + backgroundTask = [options valueForKey:@"IOSBackgroundTask"] == nil ? NO : [[options valueForKey:@"IOSBackgroundTask"] boolValue]; followRedirect = [options valueForKey:@"followRedirect"] == nil ? YES : [[options valueForKey:@"followRedirect"] boolValue]; isIncrement = [options valueForKey:@"increment"] == nil ? NO : [[options valueForKey:@"increment"] boolValue]; @@ -246,7 +246,9 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options // network status indicator if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES) - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; + }); __block UIApplication * app = [UIApplication sharedApplication]; } @@ -483,7 +485,9 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom NSString * respStr = [NSNull null]; NSString * rnfbRespType = @""; - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; + }); if(respInfo == nil) {