# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1616898200 0 # Node ID b28852b35452bc048b6c36587f1d26dd75b40ae3 # Parent 010ae32a50674f85d161aeaf6a7488a9732bbe47 iOS: Fix message boxes... the hiddenWindow they are attached to was being created in DWObject initialization which was happening before UIApplicationMain() thus did not function. Delay creation in delayedInit: diff -r 010ae32a5067 -r b28852b35452 ios/dw.m --- a/ios/dw.m Sat Mar 27 19:18:36 2021 +0000 +++ b/ios/dw.m Sun Mar 28 02:23:20 2021 +0000 @@ -871,11 +871,19 @@ -(id)init { self = [super init]; + /* This previously had the code in delayedIinit: */ + return self; +} +-(void)delayedInit:(id)param +{ + /* When DWObject is initialized, UIApplicationMain() has not yet been called... + * So the created objects can't interact with the user interface... therefore + * we wait until UIApplicationMain() has been called and run this then. + */ hiddenWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - [hiddenWindow setBackgroundColor:[UIColor clearColor]]; - [hiddenWindow setWindowLevel:UIWindowLevelAlert]; + [hiddenWindow setWindowLevel:UIWindowLevelAlert+1]; [hiddenWindow setHidden:YES]; - return self; + [hiddenWindow setRootViewController:[UIViewController new]]; } -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } -(void)menuHandler:(id)param @@ -890,28 +898,34 @@ } -(void)messageBox:(NSMutableArray *)params { - __block NSInteger iResponse = 0; + __block DWDialog *dialog = dw_dialog_new(NULL); + NSInteger iResponse; UIAlertController* alert = [UIAlertController alertControllerWithTitle:[params objectAtIndex:0] message:[params objectAtIndex:1] preferredStyle:[[params objectAtIndex:2] integerValue]]; - UIAlertAction* action = [UIAlertAction actionWithTitle:[params objectAtIndex:3] style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { iResponse = 1; }]; + handler:^(UIAlertAction * action) { dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(1)); }]; [alert addAction:action]; if([params count] > 4) + { action = [UIAlertAction actionWithTitle:[params objectAtIndex:4] style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { iResponse = 2; }]; - [alert addAction:action]; + handler:^(UIAlertAction * action) { dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(2)); }]; + [alert addAction:action]; + } if([params count] > 5) + { action = [UIAlertAction actionWithTitle:[params objectAtIndex:5] style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { iResponse = 3; }]; - [alert addAction:action]; + handler:^(UIAlertAction * action) { dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(3)); }]; + [alert addAction:action]; + } /* Unhide our hidden window and make it key */ [hiddenWindow setHidden:NO]; [hiddenWindow makeKeyAndVisible]; [[hiddenWindow rootViewController] presentViewController:alert animated:YES completion:nil]; + iResponse = DW_POINTER_TO_INT(dw_dialog_wait(dialog)); /* Once the dialog is gone we can rehide our window */ + [hiddenWindow resignKeyWindow]; [hiddenWindow setHidden:YES]; [params addObject:[NSNumber numberWithInteger:iResponse]]; } @@ -2495,8 +2509,6 @@ */ void API dw_shutdown(void) { - NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key); - [pool drain]; } /* @@ -2631,8 +2643,12 @@ mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease]; va_end(args); +#if 0 /* TODO: If we want to use this style it requires a rectangle... + * However the alert style looks pretty good to me... + */ if(flags & DW_MB_INFORMATION) mstyle = UIAlertControllerStyleActionSheet; +#endif params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil]; [DWObj safeCall:@selector(messageBox:) withObject:params]; @@ -7336,6 +7352,7 @@ DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; DWView *view = [[DWView alloc] init]; + [window setWindowLevel:UIWindowLevelNormal]; [window setRootViewController:[[DWViewController alloc] init]]; [window addSubview:view]; @@ -9681,6 +9698,7 @@ DWApp = [UIApplication sharedApplication]; } dw_event_reset(DWMainEvent); + [DWObj performSelectorOnMainThread:@selector(delayedInit:) withObject:nil waitUntilDone:YES]; } /*