With JavaScript, you can open a URL in a specific browser tab.
How do you accomplish the same thing with Swift from an iOS app, i.e., open URL in Safari/Chrome in a specific tab.
The UIApplication
open function doesn't list information about the options
parameter, which seems like it might let you specify a named tab in which to open the URL.
This is how I open links in Google Chrome:
var newLink: String = "http://www.apple.com"
newLink = link.replacingOccurrences(of: "http://", with: "googlechrome://")
if UIApplication.sharedApplication().canOpenURL(NSURL(string: newLink)!) {
UIApplication.sharedApplication().openURL(NSURL(string: newLink)!)
} else {
let alertController = UIAlertController(title: "Sorry", message: "Google Chrome app is not installed", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
Opera Mini:
opera://open-url?url=http://
Opera Touch:
touch-https://
Firefox:
firefox://open-url?url=http://
Dolphin:
dolphin://
Brave:
brave://open-url?url=http://
Change the protocol detail (HTTP or HTTPS) of the url to googlechrome and the application will open the link in Chrome:
let sUrl = "googlechrome://www.google.com"
UIApplication.shared.openURL(NSURL(string: sUrl) as! URL)
In the end I just got Google Chrome (on iOS) to do all the donkey-work (it appears willing to save the password for this website for future retrieval). I also submitted in the URL for the HTTPS version of the website and now all appear to work a little better.
if URL(string: fullURL) != nil {
//let safariVC = SFSafariViewController(url: url)
//self.present(safariVC, animated: true, completion: nil)
UIApplication.shared.openURL(NSURL(string: fullURL)! as URL)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With