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。有什么想法吗?
发布于 2018-03-02 17:08:09
由于您在代码中替换了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的替换中释放
https://stackoverflow.com/questions/49065193
复制相似问题