I recently ran into an problem with one of our clients who have a very slow internet connection and also use GroundControl. Anytime they try to load my app, they get stuck on the "Attemping to Connect to Server" loading screen. I know that in code that it must be getting stuck here (see code below), because neither the success or failure are ever called (if they were the app would at least advance).
NSURL *ourTable = [NSURL URLWithString:[[NSString stringWithFormat: @"%@://%@%@/bla/%@/bla/bla/Reachability",
(useSSLB == YES) ? @"https" : @"http", server, port, self.globalSettings.env]
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:ourTable.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"ONLINE..");
[self.ourSyncClass functionThatGetsCalledWhenSuccess;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(syncOther) userInfo:nil repeats:NO];
startSync = YES; //Bool value used for other stuffs
NSLog(@"Syncing Data");
[manager invalidateSessionCancelingTasks:YES];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"FAILED TO CONNECT TO SERVER. %@", error);
self.offline = YES; //bool used for other stuff
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[self.homeViewControllerInstance.syncView setAlpha:0.0];
[UIView commitAnimations];
[self.ourSyncClass createDB];
[self.ourSyncClass openDB];
[self startCustomFunction;
[manager invalidateSessionCancelingTasks:YES];
}];
Why does our code get stuck (locked?) in this GET completion block? Is it due to a slow internet connection? Could it possibly have something to do with GroundControl? How can I handle this type of situation?