Skip to content
Permalink
Browse files
Merge pull request #534 from GEDYSIntraWare/fix-show-ios13
Fix inappbrowser not opening on iOS 13 by using reusable window. Resolves #492
  • Loading branch information
dpa99c committed Sep 24, 2019
2 parents 2b59941 + 8553946 commit ba345b01595862173f650266a2e84ec7b4b3549b
Showing 2 changed files with 27 additions and 12 deletions.
@@ -27,6 +27,8 @@
@class CDVWKInAppBrowserViewController;

@interface CDVWKInAppBrowser : CDVPlugin {
UIWindow * tmpWindow;

@private
NSString* _beforeload;
BOOL _waitForBeforeload;
@@ -80,6 +80,7 @@ - (void)close:(CDVInvokedUrlCommand*)command
NSLog(@"IAB.close() called but it was already closed.");
return;
}

// Things are cleaned up in browserExit.
[self.inAppBrowserViewController close];
}
@@ -275,7 +276,9 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
_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{
@@ -314,19 +317,21 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
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;
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf->tmpWindow) {
CGRect frame = [[UIScreen mainScreen] bounds];
if(initHidden && osVersion < 11){
frame.origin.x = -10000;
}
strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame];
}

UIWindow *tmpWindow = [[UIWindow alloc] initWithFrame:frame];
UIViewController *tmpController = [[UIViewController alloc] init];
[tmpWindow setRootViewController:tmpController];
[tmpWindow setWindowLevel:UIWindowLevelNormal];

[strongSelf->tmpWindow setRootViewController:tmpController];
[strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];

if(!initHidden || osVersion < 11){
[tmpWindow makeKeyAndVisible];
[self->tmpWindow makeKeyAndVisible];
}
[tmpController presentViewController:nav animated:!noAnimate completion:nil];
}
@@ -335,6 +340,10 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate

- (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;
@@ -690,6 +699,10 @@ - (void)browserExit
// 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) {
@@ -786,7 +799,7 @@ - (void)createViews

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
if (@available(iOS 11.0, *)) {
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
#endif

0 comments on commit ba345b0

Please sign in to comment.