我正在使用以下代码打开 URL SFSafariViewController
:
import UIKit
import SafariServices
class ViewController: UIViewController, UITextViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
openBrowser(url: "https://www.example.com")
}
fileprivate func openBrowser(url: String) {
let svc = SFSafariViewController(url: NSURL(string: url)! as URL, entersReaderIfAvailable: false)
svc.delegate = self
present(svc, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension ViewController: SFSafariViewControllerDelegate {
func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
}
func safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] {
return []
}
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
}
}
这工作得很好。
但是,如果该网站包含一个链接target="_blank"
并且我单击它,则不会发生任何事情。
我知道它SFSafariViewController
不支持多个窗口或选项卡。
但我认为应该有可能忽略target="_blank"
并打开链接,就像没有target="_blank"
.
有什么办法可以做到这一点?