From 2d30ccfd121fcdea49a7ee3b72ca36faa70e21e2 Mon Sep 17 00:00:00 2001 From: Pavel Chuchuva Date: Tue, 22 Nov 2016 12:02:15 +1100 Subject: [PATCH 1/3] Add closing Browser Tab on iOS Fixes #4 See https://github.com/google/cordova-plugin-browsertab/issues/4 --- plugin/src/ios/CBTBrowserTab.h | 6 ++++++ plugin/src/ios/CBTBrowserTab.m | 12 +++++++++--- plugin/www/browsertab.js | 9 +++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugin/src/ios/CBTBrowserTab.h b/plugin/src/ios/CBTBrowserTab.h index 10127c4..3a3c2db 100644 --- a/plugin/src/ios/CBTBrowserTab.h +++ b/plugin/src/ios/CBTBrowserTab.h @@ -18,8 +18,14 @@ #import @interface CBTBrowserTab : CDVPlugin +{ + @protected + SFSafariViewController* _safari; +} - (void) isAvailable:(CDVInvokedUrlCommand*)command; - (void) openUrl:(CDVInvokedUrlCommand*)command; +- (void) close:(CDVInvokedUrlCommand*)command; + @end diff --git a/plugin/src/ios/CBTBrowserTab.m b/plugin/src/ios/CBTBrowserTab.m index f726aef..96dd411 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]; + _safari = [[SFSafariViewController alloc] initWithURL: url]; - [self.viewController presentViewController:sfvc + [self.viewController presentViewController:_safari animated:YES completion:nil]; @@ -63,4 +62,11 @@ - (void) openUrl:(CDVInvokedUrlCommand*)command { callbackId:command.callbackId]; } +- (void) close:(CDVInvokedUrlCommand*)command { + if (!_safari) + return; + [_safari dismissViewControllerAnimated:YES completion:nil]; + _safari = nil; +} + @end diff --git a/plugin/www/browsertab.js b/plugin/www/browsertab.js index 9cec343..0e94395 100644 --- a/plugin/www/browsertab.js +++ b/plugin/www/browsertab.js @@ -1,3 +1,4 @@ +cordova.define("cordova-plugin-browsertab.BrowserTab", function(require, exports, module) { /* * Copyright 2016 Google Inc. All Rights Reserved. * @@ -23,3 +24,11 @@ exports.openUrl = function(url, opt_error) { var error = (!opt_error) ? doNothing : opt_error; 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', []); +}; + +}); From ab8ed222219f1032c9b3d70b8a0215719c136380 Mon Sep 17 00:00:00 2001 From: Pavel Chuchuva Date: Tue, 22 Nov 2016 12:06:43 +1100 Subject: [PATCH 2/3] Remove redundant cordova.define call Oops --- plugin/www/browsertab.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugin/www/browsertab.js b/plugin/www/browsertab.js index 0e94395..3444263 100644 --- a/plugin/www/browsertab.js +++ b/plugin/www/browsertab.js @@ -1,4 +1,3 @@ -cordova.define("cordova-plugin-browsertab.BrowserTab", function(require, exports, module) { /* * Copyright 2016 Google Inc. All Rights Reserved. * @@ -30,5 +29,3 @@ exports.close = function(opt_error) { var error = (!opt_error) ? doNothing : opt_error; exec(doNothing, error, 'BrowserTab', 'close', []); }; - -}); From c2e4f8fca34e345fb87c0f4aa192e8ace9f42e92 Mon Sep 17 00:00:00 2001 From: Pavel Chuchuva Date: Sun, 27 Nov 2016 17:18:48 +1100 Subject: [PATCH 3/3] Fix code style --- plugin/src/ios/CBTBrowserTab.h | 11 +++++------ plugin/src/ios/CBTBrowserTab.m | 11 ++++++----- plugin/www/browsertab.js | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugin/src/ios/CBTBrowserTab.h b/plugin/src/ios/CBTBrowserTab.h index 3a3c2db..2b7338f 100644 --- a/plugin/src/ios/CBTBrowserTab.h +++ b/plugin/src/ios/CBTBrowserTab.h @@ -17,15 +17,14 @@ #import #import -@interface CBTBrowserTab : CDVPlugin -{ +@interface CBTBrowserTab : CDVPlugin { @protected - SFSafariViewController* _safari; + SFSafariViewController* _safariViewController; } -- (void) isAvailable:(CDVInvokedUrlCommand*)command; -- (void) openUrl:(CDVInvokedUrlCommand*)command; -- (void) close:(CDVInvokedUrlCommand*)command; +- (void)isAvailable:(CDVInvokedUrlCommand* )command; +- (void)openUrl:(CDVInvokedUrlCommand* )command; +- (void)close:(CDVInvokedUrlCommand *)command;; @end diff --git a/plugin/src/ios/CBTBrowserTab.m b/plugin/src/ios/CBTBrowserTab.m index 96dd411..f963b50 100644 --- a/plugin/src/ios/CBTBrowserTab.m +++ b/plugin/src/ios/CBTBrowserTab.m @@ -50,9 +50,9 @@ - (void) openUrl:(CDVInvokedUrlCommand*)command { callbackId:command.callbackId]; } - _safari = [[SFSafariViewController alloc] initWithURL: url]; + _safariViewController = [[SFSafariViewController alloc] initWithURL:url]; - [self.viewController presentViewController:_safari + [self.viewController presentViewController:_safariViewController animated:YES completion:nil]; @@ -63,10 +63,11 @@ - (void) openUrl:(CDVInvokedUrlCommand*)command { } - (void) close:(CDVInvokedUrlCommand*)command { - if (!_safari) + if (!_safariViewController) { return; - [_safari dismissViewControllerAnimated:YES completion:nil]; - _safari = nil; + } + [_safariViewController dismissViewControllerAnimated:YES completion:nil]; + _safariViewController = nil; } @end diff --git a/plugin/www/browsertab.js b/plugin/www/browsertab.js index 3444263..1157b2d 100644 --- a/plugin/www/browsertab.js +++ b/plugin/www/browsertab.js @@ -15,17 +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', []); + exec(doNothing, error, 'BrowserTab', 'close', []); };