Skip to content
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

Add closing Browser Tab on iOS #6

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 8 additions & 3 deletions plugin/src/ios/CBTBrowserTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
#import <Cordova/CDVPlugin.h>
#import <SafariServices/SafariServices.h>

@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
13 changes: 10 additions & 3 deletions plugin/src/ios/CBTBrowserTab.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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
10 changes: 8 additions & 2 deletions plugin/www/browsertab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', []);
};