我在應用程式中啟動 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
}
uj5u.com熱心網友回復:
您不需要關閉內部的控制器safariViewControllerDidFinish,點擊完成時它已經被關閉。
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://www.uj5u.com/net/348887.html
上一篇:在MVVM中初始化視圖模型
