From 8810c6a8a0300eef154246c1007acfc862238e57 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Fri, 6 Sep 2019 08:29:55 +0200 Subject: [PATCH 1/6] (ios) Fix inappbrowser not opening on iOS 13 by using reusable window Closes #492 --- src/ios/CDVWKInAppBrowser.h | 2 ++ src/ios/CDVWKInAppBrowser.m | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.h b/src/ios/CDVWKInAppBrowser.h index 1f359b1..7fddf9c 100644 --- a/src/ios/CDVWKInAppBrowser.h +++ b/src/ios/CDVWKInAppBrowser.h @@ -27,6 +27,8 @@ @class CDVWKInAppBrowserViewController; @interface CDVWKInAppBrowser : CDVPlugin { + UIWindow * tmpWindow; + @private NSString* _beforeload; BOOL _waitForBeforeload; diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index 3b039f5..e03d5c9 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -314,17 +314,18 @@ static CDVWKInAppBrowser* instance = nil; dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.inAppBrowserViewController != nil) { float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; - CGRect frame = [[UIScreen mainScreen] bounds]; - if(initHidden && osVersion < 11){ - frame.origin.x = -10000; + if (!tmpWindow) { + CGRect frame = [[UIScreen mainScreen] bounds]; + if(initHidden && osVersion < 11){ + frame.origin.x = -10000; + } + tmpWindow = [[UIWindow alloc] initWithFrame:frame]; } - - UIWindow *tmpWindow = [[UIWindow alloc] initWithFrame:frame]; UIViewController *tmpController = [[UIViewController alloc] init]; - + [tmpWindow setRootViewController:tmpController]; [tmpWindow setWindowLevel:UIWindowLevelNormal]; - + if(!initHidden || osVersion < 11){ [tmpWindow makeKeyAndVisible]; } From 8805f5d46aeda0195b0883f5cc5f0c4c59eca813 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Fri, 6 Sep 2019 13:53:36 +0200 Subject: [PATCH 2/6] Finish revert and correct Xcode warnings --- src/ios/CDVWKInAppBrowser.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index e03d5c9..02aa80d 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -314,20 +314,20 @@ static CDVWKInAppBrowser* instance = nil; dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.inAppBrowserViewController != nil) { float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; - if (!tmpWindow) { + if (!self->tmpWindow) { CGRect frame = [[UIScreen mainScreen] bounds]; if(initHidden && osVersion < 11){ frame.origin.x = -10000; } - tmpWindow = [[UIWindow alloc] initWithFrame:frame]; + self->tmpWindow = [[UIWindow alloc] initWithFrame:frame]; } UIViewController *tmpController = [[UIViewController alloc] init]; - [tmpWindow setRootViewController:tmpController]; - [tmpWindow setWindowLevel:UIWindowLevelNormal]; + [self->tmpWindow setRootViewController:tmpController]; + [self->tmpWindow setWindowLevel:UIWindowLevelNormal]; if(!initHidden || osVersion < 11){ - [tmpWindow makeKeyAndVisible]; + [self->tmpWindow makeKeyAndVisible]; } [tmpController presentViewController:nav animated:!noAnimate completion:nil]; } @@ -787,7 +787,7 @@ BOOL isExiting = FALSE; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 if (@available(iOS 11.0, *)) { - [self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; + [self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; } #endif From 81bec095266ffccecbb052408445259c00f27344 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Fri, 6 Sep 2019 14:14:51 +0200 Subject: [PATCH 3/6] (ios) Fix iOS 13 show not working Removed tmpWindow and controller. This was introduced to fix IAB with WKWebView before WKIAB existed. --- src/ios/CDVWKInAppBrowser.h | 2 -- src/ios/CDVWKInAppBrowser.m | 24 ++++-------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.h b/src/ios/CDVWKInAppBrowser.h index 7fddf9c..1f359b1 100644 --- a/src/ios/CDVWKInAppBrowser.h +++ b/src/ios/CDVWKInAppBrowser.h @@ -27,8 +27,6 @@ @class CDVWKInAppBrowserViewController; @interface CDVWKInAppBrowser : CDVPlugin { - UIWindow * tmpWindow; - @private NSString* _beforeload; BOOL _waitForBeforeload; diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index 02aa80d..f176a91 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -275,7 +275,9 @@ static CDVWKInAppBrowser* instance = nil; _waitForBeforeload = ![_beforeload isEqualToString:@""]; [self.inAppBrowserViewController navigateTo:url]; - [self show:nil withNoAnimate:browserOptions.hidden]; + if (!browserOptions.hidden) { + [self show:nil withNoAnimate:browserOptions.hidden]; + } } - (void)show:(CDVInvokedUrlCommand*)command{ @@ -312,25 +314,7 @@ static CDVWKInAppBrowser* instance = nil; // Run later to avoid the "took a long time" log message. dispatch_async(dispatch_get_main_queue(), ^{ - if (weakSelf.inAppBrowserViewController != nil) { - float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; - if (!self->tmpWindow) { - CGRect frame = [[UIScreen mainScreen] bounds]; - if(initHidden && osVersion < 11){ - frame.origin.x = -10000; - } - self->tmpWindow = [[UIWindow alloc] initWithFrame:frame]; - } - UIViewController *tmpController = [[UIViewController alloc] init]; - - [self->tmpWindow setRootViewController:tmpController]; - [self->tmpWindow setWindowLevel:UIWindowLevelNormal]; - - if(!initHidden || osVersion < 11){ - [self->tmpWindow makeKeyAndVisible]; - } - [tmpController presentViewController:nav animated:!noAnimate completion:nil]; - } + [weakSelf.viewController presentViewController:nav animated:!noAnimate completion:nil]; }); } From 82d496ae5cdbbc7f46ce20c77d6ad7bcbe2fb207 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Fri, 20 Sep 2019 13:43:57 +0200 Subject: [PATCH 4/6] Use tmpWindow and hide on close --- src/ios/CDVWKInAppBrowser.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index 02aa80d..fdc88dc 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -80,6 +80,11 @@ static CDVWKInAppBrowser* instance = nil; NSLog(@"IAB.close() called but it was already closed."); return; } + + // 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; + // Things are cleaned up in browserExit. [self.inAppBrowserViewController close]; } @@ -314,17 +319,18 @@ static CDVWKInAppBrowser* instance = nil; dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.inAppBrowserViewController != nil) { float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; - if (!self->tmpWindow) { + __strong __typeof(weakSelf) strongSelf = weakSelf; + if (!strongSelf->tmpWindow) { CGRect frame = [[UIScreen mainScreen] bounds]; if(initHidden && osVersion < 11){ frame.origin.x = -10000; } - self->tmpWindow = [[UIWindow alloc] initWithFrame:frame]; + strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame]; } UIViewController *tmpController = [[UIViewController alloc] init]; - [self->tmpWindow setRootViewController:tmpController]; - [self->tmpWindow setWindowLevel:UIWindowLevelNormal]; + [strongSelf->tmpWindow setRootViewController:tmpController]; + [strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal]; if(!initHidden || osVersion < 11){ [self->tmpWindow makeKeyAndVisible]; From 79b1bb61a06ad64615a604e1c567ef2362ec7a17 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Mon, 23 Sep 2019 10:29:31 +0200 Subject: [PATCH 5/6] Move window hiding to 'browserExit' Fixes close, hide and toolbar 'done' and makes cordova window responsive --- src/ios/CDVWKInAppBrowser.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index b5fb174..96d9fa9 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -81,10 +81,6 @@ static CDVWKInAppBrowser* instance = nil; return; } - // 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; - // Things are cleaned up in browserExit. [self.inAppBrowserViewController close]; } @@ -699,6 +695,10 @@ static CDVWKInAppBrowser* instance = nil; // Set navigationDelegate to nil to ensure no callbacks are received from it. self.inAppBrowserViewController.navigationDelegate = nil; 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) { From 855394628e60f27eb813157918e26f1cf3f54b9c Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 24 Sep 2019 16:28:07 +0200 Subject: [PATCH 6/6] Fix unresponsive main window after hide --- src/ios/CDVWKInAppBrowser.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index 96d9fa9..f937714 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -340,6 +340,10 @@ static CDVWKInAppBrowser* instance = nil; - (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;