Fix crash when the loading spinner is dismissed before fully presenting

This commit is contained in:
Cameron Gutman
2018-11-15 22:02:05 -08:00
parent eefde316de
commit 23e9c3f236
@@ -302,7 +302,7 @@ static NSMutableSet* hostList;
return; return;
} }
[self showLoadingFrame]; [self showLoadingFrame: ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
HttpManager* hMan = [[HttpManager alloc] initWithHost:host.activeAddress uniqueId:self->_uniqueId deviceName:deviceName cert:self->_cert]; HttpManager* hMan = [[HttpManager alloc] initWithHost:host.activeAddress uniqueId:self->_uniqueId deviceName:deviceName cert:self->_cert];
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
@@ -317,6 +317,7 @@ static NSMutableSet* hostList;
Log(LOG_W, @"Failed to get server info: %@", serverInfoResp.statusMessage); Log(LOG_W, @"Failed to get server info: %@", serverInfoResp.statusMessage);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (host != self->_selectedHost) { if (host != self->_selectedHost) {
[self hideLoadingFrame:nil];
return; return;
} }
@@ -361,6 +362,7 @@ static NSMutableSet* hostList;
} }
} }
}); });
}];
} }
- (UIViewController*) activeViewController { - (UIViewController*) activeViewController {
@@ -422,7 +424,7 @@ static NSMutableSet* hostList;
- (void) addHostClicked { - (void) addHostClicked {
Log(LOG_D, @"Clicked add host"); Log(LOG_D, @"Clicked add host");
[self showLoadingFrame]; [self showLoadingFrame: ^{
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:@"Host Address" message:@"Please enter a hostname or IP address" preferredStyle:UIAlertControllerStyleAlert]; UIAlertController* alertController = [UIAlertController alertControllerWithTitle:@"Host Address" message:@"Please enter a hostname or IP address" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){ [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
@@ -450,6 +452,7 @@ static NSMutableSet* hostList;
[self hideLoadingFrame: ^{ [self hideLoadingFrame: ^{
[[self activeViewController] presentViewController:alertController animated:YES completion:nil]; [[self activeViewController] presentViewController:alertController animated:YES completion:nil];
}]; }];
}];
} }
- (void) prepareToStreamApp:(TemporaryApp *)app { - (void) prepareToStreamApp:(TemporaryApp *)app {
@@ -522,7 +525,7 @@ static NSMutableSet* hostList;
[alertController addAction:[UIAlertAction actionWithTitle: [alertController addAction:[UIAlertAction actionWithTitle:
[app.id isEqualToString:currentApp.id] ? @"Quit App" : @"Quit Running App and Start" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){ [app.id isEqualToString:currentApp.id] ? @"Quit App" : @"Quit Running App and Start" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
Log(LOG_I, @"Quitting application: %@", currentApp.name); Log(LOG_I, @"Quitting application: %@", currentApp.name);
[self showLoadingFrame]; [self showLoadingFrame: ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
HttpManager* hMan = [[HttpManager alloc] initWithHost:app.host.activeAddress uniqueId:self->_uniqueId deviceName:deviceName cert:self->_cert]; HttpManager* hMan = [[HttpManager alloc] initWithHost:app.host.activeAddress uniqueId:self->_uniqueId deviceName:deviceName cert:self->_cert];
HttpResponse* quitResponse = [[HttpResponse alloc] init]; HttpResponse* quitResponse = [[HttpResponse alloc] init];
@@ -584,6 +587,8 @@ static NSMutableSet* hostList;
}]; }];
}); });
}); });
}];
}]]; }]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[[self activeViewController] presentViewController:alertController animated:YES completion:nil]; [[self activeViewController] presentViewController:alertController animated:YES completion:nil];
@@ -650,11 +655,11 @@ static NSMutableSet* hostList;
} }
} }
- (void) showLoadingFrame { - (void) showLoadingFrame:(void (^)(void))completion {
// Avoid animating this as it significantly prolongs the loading frame's // Avoid animating this as it significantly prolongs the loading frame's
// time on screen and can lead to warnings about dismissing while it's // time on screen and can lead to warnings about dismissing while it's
// still animating. // still animating.
[[self activeViewController] presentViewController:_loadingFrame animated:NO completion:nil]; [[self activeViewController] presentViewController:_loadingFrame animated:NO completion:completion];
} }
- (void) hideLoadingFrame:(void (^)(void))completion { - (void) hideLoadingFrame:(void (^)(void))completion {