实现 SFSafariViewControllerDelegate

你应该实现 SFSafariViewControllerDelegate,以便当用户点击 SafariViewController 上的 Done 按钮时通知你的类,你也可以解雇它。

首先声明你的类来实现协议。

class MyClass: SFSafariViewControllerDelegate {

}

实施委托方法以获得解雇通知。

func safariViewControllerDidFinish(controller: SFSafariViewController) {
    // Dismiss the SafariViewController when done
    controller.dismissViewControllerAnimated(true, completion: nil)
}

不要忘记将你的类设置为 SafariViewController 的委托。

let safariVC = SFSafariViewController(URL: yourURL)
safariVC.delegate = self

你可以实现的其他委托方法是:

// Called when the initial URL load is complete.
safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { }

// Called when the user taps an Action button.
safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] { }