diff --git a/plugin/src/ios/CBTBrowserTab.h b/plugin/src/ios/CBTBrowserTab.h index 10127c4..2b7338f 100644 --- a/plugin/src/ios/CBTBrowserTab.h +++ b/plugin/src/ios/CBTBrowserTab.h @@ -17,9 +17,14 @@ #import #import -@interface CBTBrowserTab : CDVPlugin +@interface CBTBrowserTab : CDVPlugin { + @protected + SFSafariViewController* _safariViewController; +} + +- (void)isAvailable:(CDVInvokedUrlCommand* )command; +- (void)openUrl:(CDVInvokedUrlCommand* )command; +- (void)close:(CDVInvokedUrlCommand *)command;; -- (void) isAvailable:(CDVInvokedUrlCommand*)command; -- (void) openUrl:(CDVInvokedUrlCommand*)command; @end diff --git a/plugin/src/ios/CBTBrowserTab.m b/plugin/src/ios/CBTBrowserTab.m index f726aef..f963b50 100644 --- a/plugin/src/ios/CBTBrowserTab.m +++ b/plugin/src/ios/CBTBrowserTab.m @@ -50,10 +50,9 @@ - (void) openUrl:(CDVInvokedUrlCommand*)command { callbackId:command.callbackId]; } - SFSafariViewController *sfvc = - [[SFSafariViewController alloc] initWithURL: url]; + _safariViewController = [[SFSafariViewController alloc] initWithURL:url]; - [self.viewController presentViewController:sfvc + [self.viewController presentViewController:_safariViewController animated:YES completion:nil]; @@ -63,4 +62,12 @@ - (void) openUrl:(CDVInvokedUrlCommand*)command { callbackId:command.callbackId]; } +- (void) close:(CDVInvokedUrlCommand*)command { + if (!_safariViewController) { + return; + } + [_safariViewController dismissViewControllerAnimated:YES completion:nil]; + _safariViewController = nil; +} + @end diff --git a/plugin/www/browsertab.js b/plugin/www/browsertab.js index 9cec343..1157b2d 100644 --- a/plugin/www/browsertab.js +++ b/plugin/www/browsertab.js @@ -15,11 +15,17 @@ var exec = require('cordova/exec'); exports.isAvailable = function(success, error) { - exec(success, error, 'BrowserTab', 'isAvailable', []); + exec(success, error, 'BrowserTab', 'isAvailable', []); }; exports.openUrl = function(url, opt_error) { var doNothing = function() {}; var error = (!opt_error) ? doNothing : opt_error; - exec(doNothing, error, 'BrowserTab', 'openUrl', [url]); + exec(doNothing, error, 'BrowserTab', 'openUrl', [url]); +}; + +exports.close = function(opt_error) { + var doNothing = function() {}; + var error = (!opt_error) ? doNothing : opt_error; + exec(doNothing, error, 'BrowserTab', 'close', []); };