diff --git a/src/ios/CDVWKInAppBrowser.h b/src/ios/CDVWKInAppBrowser.h index f8263f707..7a3afbf27 100644 --- a/src/ios/CDVWKInAppBrowser.h +++ b/src/ios/CDVWKInAppBrowser.h @@ -75,6 +75,7 @@ - (void)showLocationBar:(BOOL)show; - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition; - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex; +- (void)updateViews: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings; - (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings; diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index aacf19297..cdd05b384 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -200,11 +200,13 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options if (self.inAppBrowserViewController == nil) { self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings]; self.inAppBrowserViewController.navigationDelegate = self; - if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) { self.inAppBrowserViewController.orientationDelegate = (UIViewController *)self.viewController; } } + else { + [self.inAppBrowserViewController updateViews:browserOptions andSettings:self.commandDelegate.settings]; + } [self.inAppBrowserViewController showLocationBar:browserOptions.location]; [self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition]; @@ -663,17 +665,18 @@ - (void)browserExit [self.inAppBrowserViewController.configuration.userContentController removeScriptMessageHandlerForName:IAB_BRIDGE_NAME]; self.inAppBrowserViewController.configuration = nil; - + [self.inAppBrowserViewController.webView stopLoading]; + [self.inAppBrowserViewController navigateTo:([NSURL URLWithString:@"about:blank"])]; [self.inAppBrowserViewController.webView removeFromSuperview]; [self.inAppBrowserViewController.webView setUIDelegate:nil]; [self.inAppBrowserViewController.webView setNavigationDelegate:nil]; - self.inAppBrowserViewController.webView = nil; - - // Set navigationDelegate to nil to ensure no callbacks are received from it. - self.inAppBrowserViewController.navigationDelegate = nil; - self.inAppBrowserViewController = nil; - + + [self.inAppBrowserViewController.spinner removeFromSuperview]; + [self.inAppBrowserViewController.toolbar removeFromSuperview]; + [self.inAppBrowserViewController.addressLabel removeFromSuperview]; + [self.inAppBrowserViewController.backgroundView removeFromSuperview]; + // 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; @@ -715,10 +718,16 @@ - (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettin return self; } --(void)dealloc { +- (void)dealloc { //NSLog(@"dealloc"); } +- (void)updateViews: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings { + _browserOptions = browserOptions; + _settings = settings; + [self createViews]; +} + - (void)createViews { // We create the views in code for primarily for ease of upgrades and not requiring an external .xib to be included @@ -748,9 +757,12 @@ - (void)createViews configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction; } - - - self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration]; + if(self.webView == nil) { + self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration]; + } + else { + self.webView.frame = webViewBounds; + } [self.view addSubview:self.webView]; [self.view sendSubviewToBack:self.webView];