Merge pull request #534 from GEDYSIntraWare/fix-show-ios13

Fix inappbrowser not opening on iOS 13 by using reusable window. Resolves #492
This commit is contained in:
Dave Alden 2019-09-24 15:43:48 +01:00 committed by GitHub
commit ba345b0159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 12 deletions

View File

@ -27,6 +27,8 @@
@class CDVWKInAppBrowserViewController; @class CDVWKInAppBrowserViewController;
@interface CDVWKInAppBrowser : CDVPlugin { @interface CDVWKInAppBrowser : CDVPlugin {
UIWindow * tmpWindow;
@private @private
NSString* _beforeload; NSString* _beforeload;
BOOL _waitForBeforeload; BOOL _waitForBeforeload;

View File

@ -80,6 +80,7 @@ static CDVWKInAppBrowser* instance = nil;
NSLog(@"IAB.close() called but it was already closed."); NSLog(@"IAB.close() called but it was already closed.");
return; return;
} }
// Things are cleaned up in browserExit. // Things are cleaned up in browserExit.
[self.inAppBrowserViewController close]; [self.inAppBrowserViewController close];
} }
@ -275,7 +276,9 @@ static CDVWKInAppBrowser* instance = nil;
_waitForBeforeload = ![_beforeload isEqualToString:@""]; _waitForBeforeload = ![_beforeload isEqualToString:@""];
[self.inAppBrowserViewController navigateTo:url]; [self.inAppBrowserViewController navigateTo:url];
if (!browserOptions.hidden) {
[self show:nil withNoAnimate:browserOptions.hidden]; [self show:nil withNoAnimate:browserOptions.hidden];
}
} }
- (void)show:(CDVInvokedUrlCommand*)command{ - (void)show:(CDVInvokedUrlCommand*)command{
@ -314,19 +317,21 @@ static CDVWKInAppBrowser* instance = nil;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (weakSelf.inAppBrowserViewController != nil) { if (weakSelf.inAppBrowserViewController != nil) {
float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf->tmpWindow) {
CGRect frame = [[UIScreen mainScreen] bounds]; CGRect frame = [[UIScreen mainScreen] bounds];
if(initHidden && osVersion < 11){ if(initHidden && osVersion < 11){
frame.origin.x = -10000; frame.origin.x = -10000;
} }
strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame];
UIWindow *tmpWindow = [[UIWindow alloc] initWithFrame:frame]; }
UIViewController *tmpController = [[UIViewController alloc] init]; UIViewController *tmpController = [[UIViewController alloc] init];
[tmpWindow setRootViewController:tmpController]; [strongSelf->tmpWindow setRootViewController:tmpController];
[tmpWindow setWindowLevel:UIWindowLevelNormal]; [strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];
if(!initHidden || osVersion < 11){ if(!initHidden || osVersion < 11){
[tmpWindow makeKeyAndVisible]; [self->tmpWindow makeKeyAndVisible];
} }
[tmpController presentViewController:nav animated:!noAnimate completion:nil]; [tmpController presentViewController:nav animated:!noAnimate completion:nil];
} }
@ -335,6 +340,10 @@ static CDVWKInAppBrowser* instance = nil;
- (void)hide:(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) { if (self.inAppBrowserViewController == nil) {
NSLog(@"Tried to hide IAB after it was closed."); NSLog(@"Tried to hide IAB after it was closed.");
return; return;
@ -691,6 +700,10 @@ static CDVWKInAppBrowser* instance = nil;
self.inAppBrowserViewController.navigationDelegate = nil; self.inAppBrowserViewController.navigationDelegate = nil;
self.inAppBrowserViewController = 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 (IsAtLeastiOSVersion(@"7.0")) {
if (_previousStatusBarStyle != -1) { if (_previousStatusBarStyle != -1) {
[[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle]; [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle];