Skip to content

Commit ba345b0

Browse files
authored
Merge pull request #534 from GEDYSIntraWare/fix-show-ios13
Fix inappbrowser not opening on iOS 13 by using reusable window. Resolves #492
2 parents 2b59941 + 8553946 commit ba345b0

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/ios/CDVWKInAppBrowser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
@class CDVWKInAppBrowserViewController;
2828

2929
@interface CDVWKInAppBrowser : CDVPlugin {
30+
UIWindow * tmpWindow;
31+
3032
@private
3133
NSString* _beforeload;
3234
BOOL _waitForBeforeload;

src/ios/CDVWKInAppBrowser.m

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ - (void)close:(CDVInvokedUrlCommand*)command
8080
NSLog(@"IAB.close() called but it was already closed.");
8181
return;
8282
}
83+
8384
// Things are cleaned up in browserExit.
8485
[self.inAppBrowserViewController close];
8586
}
@@ -275,7 +276,9 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
275276
_waitForBeforeload = ![_beforeload isEqualToString:@""];
276277

277278
[self.inAppBrowserViewController navigateTo:url];
278-
[self show:nil withNoAnimate:browserOptions.hidden];
279+
if (!browserOptions.hidden) {
280+
[self show:nil withNoAnimate:browserOptions.hidden];
281+
}
279282
}
280283

281284
- (void)show:(CDVInvokedUrlCommand*)command{
@@ -314,19 +317,21 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
314317
dispatch_async(dispatch_get_main_queue(), ^{
315318
if (weakSelf.inAppBrowserViewController != nil) {
316319
float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
317-
CGRect frame = [[UIScreen mainScreen] bounds];
318-
if(initHidden && osVersion < 11){
319-
frame.origin.x = -10000;
320+
__strong __typeof(weakSelf) strongSelf = weakSelf;
321+
if (!strongSelf->tmpWindow) {
322+
CGRect frame = [[UIScreen mainScreen] bounds];
323+
if(initHidden && osVersion < 11){
324+
frame.origin.x = -10000;
325+
}
326+
strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame];
320327
}
321-
322-
UIWindow *tmpWindow = [[UIWindow alloc] initWithFrame:frame];
323328
UIViewController *tmpController = [[UIViewController alloc] init];
324-
325-
[tmpWindow setRootViewController:tmpController];
326-
[tmpWindow setWindowLevel:UIWindowLevelNormal];
327-
329+
330+
[strongSelf->tmpWindow setRootViewController:tmpController];
331+
[strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];
332+
328333
if(!initHidden || osVersion < 11){
329-
[tmpWindow makeKeyAndVisible];
334+
[self->tmpWindow makeKeyAndVisible];
330335
}
331336
[tmpController presentViewController:nav animated:!noAnimate completion:nil];
332337
}
@@ -335,6 +340,10 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
335340

336341
- (void)hide:(CDVInvokedUrlCommand*)command
337342
{
343+
// Set tmpWindow to hidden to make main webview responsive to touch again
344+
// https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
345+
self->tmpWindow.hidden = YES;
346+
338347
if (self.inAppBrowserViewController == nil) {
339348
NSLog(@"Tried to hide IAB after it was closed.");
340349
return;
@@ -690,6 +699,10 @@ - (void)browserExit
690699
// Set navigationDelegate to nil to ensure no callbacks are received from it.
691700
self.inAppBrowserViewController.navigationDelegate = nil;
692701
self.inAppBrowserViewController = nil;
702+
703+
// Set tmpWindow to hidden to make main webview responsive to touch again
704+
// Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
705+
self->tmpWindow.hidden = YES;
693706

694707
if (IsAtLeastiOSVersion(@"7.0")) {
695708
if (_previousStatusBarStyle != -1) {
@@ -786,7 +799,7 @@ - (void)createViews
786799

787800
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
788801
if (@available(iOS 11.0, *)) {
789-
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
802+
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
790803
}
791804
#endif
792805

0 commit comments

Comments
 (0)