Skip to content

Commit

Permalink
(ios) Fix inappbrowser not opening on iOS 13 by using reusable window
Browse files Browse the repository at this point in the history
Closes #492
  • Loading branch information
NiklasMerz committed Sep 6, 2019
1 parent 2b59941 commit 480e8da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/ios/CDVWKInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
@class CDVWKInAppBrowserViewController;

@interface CDVWKInAppBrowser : CDVPlugin {
UIWindow * tmpWindow;

@private
NSString* _beforeload;
BOOL _waitForBeforeload;
Expand Down
19 changes: 7 additions & 12 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,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{
Expand Down Expand Up @@ -313,22 +315,15 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
// Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{
if (weakSelf.inAppBrowserViewController != nil) {
float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (!tmpWindow) {
CGRect frame = [[UIScreen mainScreen] bounds];
if(initHidden && osVersion < 11){
frame.origin.x = -10000;
tmpWindow = [[UIWindow alloc] initWithFrame:frame];
}

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

[tmpWindow setRootViewController:tmpController];
[tmpWindow setWindowLevel:UIWindowLevelNormal];

if(!initHidden || osVersion < 11){

[tmpWindow makeKeyAndVisible];
}
[tmpController presentViewController:nav animated:!noAnimate completion:nil];
[tmpController presentViewController:nav animated:YES completion:nil];
}
});
}
Expand Down

0 comments on commit 480e8da

Please sign in to comment.