我最近遇到了我们的一位客户的问题,他们的互联网连接速度非常慢,并且还使用 GroundControl。每当他们尝试加载我的应用程序时,他们都会卡在“尝试连接到服务器”加载屏幕上。我知道在代码中它必须卡在这里(参见下面的代码),因为从来没有调用成功或失败(如果它们是应用程序至少会前进)。
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];
}];
为什么我们的代码会在这个 GET 完成块中卡住(锁定?)?是因为网速慢吗?它可能与地面控制有关吗?我该如何处理这种情况?