Skip to content

Fix/Persist inappbrowser webview across different calls #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: outsystems
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ios/CDVWKInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
36 changes: 24 additions & 12 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CDVScreenOrientationDelegate>*)self.viewController;
}
}
else {
[self.inAppBrowserViewController updateViews:browserOptions andSettings:self.commandDelegate.settings];
}

[self.inAppBrowserViewController showLocationBar:browserOptions.location];
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down