Skip to content

Commit

Permalink
Port fix from upstream/master from pull request (apache#534) to fix t…
Browse files Browse the repository at this point in the history
…he window not opening on iOS 13.
  • Loading branch information
Rory Grandin committed Apr 28, 2020
1 parent 1554d74 commit c569a64
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/ios/CDVUIInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,29 @@ - (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) {
if (!tmpWindow) {
CGRect frame = [[UIScreen mainScreen] bounds];
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 makeKeyAndVisible];
[strongSelf->tmpWindow setRootViewController:tmpController];
[strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];

[self->tmpWindow makeKeyAndVisible];
[tmpController presentViewController:nav animated:YES completion: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;
Expand Down Expand Up @@ -465,7 +473,7 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*
BOOL useBeforeLoad = NO;
NSString* httpMethod = request.HTTPMethod;
NSString* errorMessage = nil;

if([_beforeload isEqualToString:@"post"]){
//TODO handle POST requests by preserving POST data then remove this condition
errorMessage = @"beforeload doesn't yet support POST requests";
Expand Down Expand Up @@ -527,11 +535,11 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"beforeload", @"url":[url absoluteString]}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];

[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
return NO;
}

if(errorMessage != nil){
NSLog(errorMessage);
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
Expand Down Expand Up @@ -604,6 +612,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) {
Expand Down

0 comments on commit c569a64

Please sign in to comment.