From c569a64dbe097f8e8ccbd3e2c8976c45ef9a3fbf Mon Sep 17 00:00:00 2001 From: Rory Grandin Date: Tue, 28 Apr 2020 10:54:35 +0200 Subject: [PATCH] Port fix from upstream/master from pull request (apache#534) to fix the window not opening on iOS 13. --- src/ios/CDVUIInAppBrowser.m | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ios/CDVUIInAppBrowser.m b/src/ios/CDVUIInAppBrowser.m index 36c3b3e8a..1c004b6a7 100644 --- a/src/ios/CDVUIInAppBrowser.m +++ b/src/ios/CDVUIInAppBrowser.m @@ -259,14 +259,18 @@ - (void)show:(CDVInvokedUrlCommand*)command // Run later to avoid the "took a long time" log message. dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.inAppBrowserViewController != nil) { - if (!tmpWindow) { - CGRect frame = [[UIScreen mainScreen] bounds]; - tmpWindow = [[UIWindow alloc] initWithFrame:frame]; + float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; + __strong __typeof(weakSelf) strongSelf = weakSelf; + if (!strongSelf->tmpWindow) { + CGRect frame = [[UIScreen mainScreen] bounds]; + strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame]; } UIViewController *tmpController = [[UIViewController alloc] init]; - [tmpWindow setRootViewController:tmpController]; - [tmpWindow makeKeyAndVisible]; + [strongSelf->tmpWindow setRootViewController:tmpController]; + [strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal]; + + [self->tmpWindow makeKeyAndVisible]; [tmpController presentViewController:nav animated:YES completion:nil]; } }); @@ -274,6 +278,10 @@ - (void)show:(CDVInvokedUrlCommand*)command - (void)hide:(CDVInvokedUrlCommand*)command { + // Set tmpWindow to hidden to make main webview responsive to touch again + // https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow + self->tmpWindow.hidden = YES; + if (self.inAppBrowserViewController == nil) { NSLog(@"Tried to hide IAB after it was closed."); return; @@ -465,7 +473,7 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest* BOOL useBeforeLoad = NO; NSString* httpMethod = request.HTTPMethod; NSString* errorMessage = nil; - + if([_beforeload isEqualToString:@"post"]){ //TODO handle POST requests by preserving POST data then remove this condition errorMessage = @"beforeload doesn't yet support POST requests"; @@ -527,11 +535,11 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest* CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"type":@"beforeload", @"url":[url absoluteString]}]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; - + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; return NO; } - + if(errorMessage != nil){ NSLog(errorMessage); CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR @@ -604,6 +612,9 @@ - (void)browserExit // Don't recycle the ViewController since it may be consuming a lot of memory. // Also - this is required for the PDF/User-Agent bug work-around. self.inAppBrowserViewController = nil; + // Set tmpWindow to hidden to make main webview responsive to touch again + // Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow + self->tmpWindow.hidden = YES; if (IsAtLeastiOSVersion(@"7.0")) { if (_previousStatusBarStyle != -1) {