實現 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] { }