0

我在应用程序中启动 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
                }
4

1 回答 1

1

你不需要关闭里面的控制器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!")
    }
}
于 2021-11-04T21:37:37.897 回答