Swift:在特定浏览器选项卡中打开URL?

使用JavaScript,您可以在特定的浏览器选项卡中打开URL。

如何使用iOS应用程序中的Swift完成相同的操作,即在特定选项卡中的Safari / Chrome中打开URL。

UIApplication 打开函数不会列出有关options参数的信息,这似乎可以让您指定用于打开URL的命名选项卡。

将url的协议详细信息(HTTP或HTTPS)更改为googlechrome,应用程序将在Chrome中打开该链接:

 let sUrl = "googlechrome://www.google.com" UIApplication.shared.openURL(NSURL(string: sUrl) as! URL) 

这是我在Google Chrome中打开链接的方式:

 var newLink: String = "http://www.apple.com" newLink = link.stringByReplacingOccurrencesOfString("http://", withString: "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:// 

Firefox

 firefox://open-url?url=http:// 

海豚

 dolphin:// 

勇敢

 brave://