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 Nov 21, 2019
1 parent 2696279 commit e5d2d9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/ios/CDVInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@class CDVInAppBrowserViewController;

@interface CDVInAppBrowser : CDVPlugin {
UIWindow * tmpWindow;
}

@property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController;
Expand Down
32 changes: 22 additions & 10 deletions src/ios/CDVInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,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) {
CGRect frame = [[UIScreen mainScreen] bounds];
UIWindow *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 setWindowLevel:UIWindowLevelNormal];

[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 @@ -438,23 +447,23 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*
NSString* eventName = [url host];
NSString* eventData = [url path];
CDVPluginResult* pluginResult = nil;

NSLog(@"Event emitted - EventName: %@, EventData: %@", eventName, eventData);

if ((eventData != nil) && ([eventData length] > 1)) {
eventData = [eventData substringFromIndex:1];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"eventemitted", @"event_name":eventName, @"event_data":eventData}];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"eventemitted", @"event_name":eventName, @"event_data":@""}];

}

[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
return NO;

}
//if is an app store link, let the system handle it, otherwise it fails to load it
else if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) {
Expand Down Expand Up @@ -516,6 +525,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 e5d2d9d

Please sign in to comment.