From dac06aa3f3ad825cbcd326c0aaf0f36ebddd0cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Sun, 1 Jul 2018 18:09:47 +0200 Subject: [PATCH] CB-12922 (ios): fix In-app browser does not cede control --- src/ios/CDVInAppBrowser.h | 1 + src/ios/CDVInAppBrowser.m | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ios/CDVInAppBrowser.h b/src/ios/CDVInAppBrowser.h index 25fae3f3e..66066b9ba 100644 --- a/src/ios/CDVInAppBrowser.h +++ b/src/ios/CDVInAppBrowser.h @@ -30,6 +30,7 @@ @class CDVInAppBrowserViewController; @interface CDVInAppBrowser : CDVPlugin { + UIWindow * tmpWindow; } @property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController; diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index c65e3e150..5bdb3e1eb 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -239,8 +239,10 @@ - (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]; + if (!tmpWindow) { + CGRect frame = [[UIScreen mainScreen] bounds]; + tmpWindow = [[UIWindow alloc] initWithFrame:frame]; + } UIViewController *tmpController = [[UIViewController alloc] init]; [tmpWindow setRootViewController:tmpController]; [tmpWindow setWindowLevel:UIWindowLevelNormal]; @@ -270,7 +272,9 @@ - (void)hide:(CDVInvokedUrlCommand*)command dispatch_async(dispatch_get_main_queue(), ^{ if (self.inAppBrowserViewController != nil) { _previousStatusBarStyle = -1; - [self.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; + [self.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{ + [[[[UIApplication sharedApplication] delegate] window] makeKeyAndVisible]; + }]; } }); } @@ -835,9 +839,13 @@ - (void)close // Run later to avoid the "took a long time" log message. dispatch_async(dispatch_get_main_queue(), ^{ if ([weakSelf respondsToSelector:@selector(presentingViewController)]) { - [[weakSelf presentingViewController] dismissViewControllerAnimated:YES completion:nil]; + [[weakSelf presentingViewController] dismissViewControllerAnimated:YES completion:^{ + [[[[UIApplication sharedApplication] delegate] window] makeKeyAndVisible]; + }]; } else { - [[weakSelf parentViewController] dismissViewControllerAnimated:YES completion:nil]; + [[weakSelf parentViewController] dismissViewControllerAnimated:YES completion:^{ + [[[[UIApplication sharedApplication] delegate] window] makeKeyAndVisible]; + }]; } }); }