From e5d2d9d44ac87c12245b211abecad541c22cdd50 Mon Sep 17 00:00:00 2001 From: Rory Grandin Date: Thu, 21 Nov 2019 11:46:06 +0200 Subject: [PATCH] Port fix from upstream/master from pull request (https://github.com/apache/cordova-plugin-inappbrowser/pull/534) to fix the window not opening on iOS 13. --- src/ios/CDVInAppBrowser.h | 1 + src/ios/CDVInAppBrowser.m | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/ios/CDVInAppBrowser.h b/src/ios/CDVInAppBrowser.h index 25fae3f3e..6636f3607 100644 --- a/src/ios/CDVInAppBrowser.h +++ b/src/ios/CDVInAppBrowser.h @@ -30,6 +30,7 @@ @class CDVInAppBrowserViewController; @interface CDVInAppBrowser : CDVPlugin { + UIWindow * tmpWindow; } @property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController; diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index 78e2186ed..3f526bb2d 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -239,13 +239,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) { - CGRect frame = [[UIScreen mainScreen] bounds]; - UIWindow *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 setWindowLevel:UIWindowLevelNormal]; - [tmpWindow makeKeyAndVisible]; + [strongSelf->tmpWindow setRootViewController:tmpController]; + [strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal]; + + [self->tmpWindow makeKeyAndVisible]; [tmpController presentViewController:nav animated:YES completion:nil]; } }); @@ -253,6 +258,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; @@ -438,9 +447,9 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest* NSString* eventName = [url host]; NSString* eventData = [url path]; CDVPluginResult* pluginResult = nil; - + NSLog(@"Event emitted - EventName: %@, EventData: %@", eventName, eventData); - + if ((eventData != nil) && ([eventData length] > 1)) { eventData = [eventData substringFromIndex:1]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK @@ -448,13 +457,13 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest* } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"type":@"eventemitted", @"event_name":eventName, @"event_data":@""}]; - + } - + [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; return NO; - + } //if is an app store link, let the system handle it, otherwise it fails to load it else if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) { @@ -516,6 +525,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) {