我在应用程序中启动Safari,并希望在按下完成后执行代码。但是func safariViewControllerDidFinish不会使用这个函数。
import SafariServices
class QRScannerController: UIViewController, WKNavigationDelegate, SFSafariViewControllerDelegate {
let vc = SFSafariViewController (url: URL(string: String(urls))!)
present(vc, animated: true, completion: nil)
vc.delegate = self
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller.dismiss(animated: true) {
// do my code
}发布于 2021-11-04 21:37:38
你不需要关闭safariViewControllerDidFinish内部的控制器,当点击done时它已经被关闭了。
import SafariServices
class QRScannerController: UIViewController, SFSafariViewControllerDelegate {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let vc = SFSafariViewController (url: URL(string: "https://www.google.com")!)
self.present(vc, animated: true, completion: nil)
vc.delegate = self
}
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
// do your code
print("done!")
}
}https://stackoverflow.com/questions/69845249
复制相似问题