Add error message when initialization fails

This commit is contained in:
Theodore Dubois 2018-01-13 14:30:27 -08:00
parent b048f6b4f6
commit 57fc5dfe9e

View File

@ -57,6 +57,11 @@ static void ios_handle_exit(int code) {
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
int err = [self startThings];
if (err < 0) {
NSString *message = [NSString stringWithFormat:@"could not initialize"];
NSString *subtitle = [NSString stringWithFormat:@"error code %d", err];
if (err == _EINVAL)
subtitle = [subtitle stringByAppendingString:@"\n(try reinstalling the app, see release notes for details)"];
[self fatal:message subtitle:subtitle];
NSLog(@"failed with code %d", err);
}
return YES;
@ -81,6 +86,15 @@ static void ios_handle_exit(int code) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (void)fatal:(NSString *)message subtitle:(NSString *)subtitle {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:message message:subtitle preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"goodbye" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
exit(0);
}]];
[self.window.rootViewController presentViewController:alert animated:YES completion:nil];
});
}
@end