class CustomScreen: UIView, SFSafariViewControllerDelegate {
@IBAction func webPageBtnAction(_ sender: Any) {
if #available(iOS 9.0, *) {
let svc = SFSafariViewController(url: NSURL(string: "https://stackoverflow.com/")! as URL)
svc.delegate = self
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = svc
} else {
// Fallback on earlier versions
}
}
@available(iOS 9.0, *)
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller.dismiss(animated: false, completion: nil)
}
}
由于某些原因,我无法解雇SFSafariViewController。有什么想法吗?
答案 0 :(得分:1)
因为在你的代码中你正在替换rootViewController
(对于这种情况来说是一种不好的做法),你应该简单地呈现SFSafariViewController
这样做:
let svc = SFSafariViewController(url: NSURL(string: "https://stackoverflow.com/")! as URL)
svc.delegate = self
UIApplication.shared.keyWindow?.rootViewController?.present(svc, animated: true, completion: nil)
据我所知,这是一种不好的做法,因为永远不会调用safariViewControllerDidFinish
,因为CustomScreen
将从当前rootViewController