Implement SFSafariViewControllerDelegate
suggest changeImplement SFSafariViewControllerDelegate so the class is notified when the user taps Done, and dismiss the controller there. The controller still has to be presented. The methods below through SFSafariViewController(URL:) are Swift 2. MyClass needs to be a type Interface Builder or UIKit can use as the delegate, such as a UIViewController.
First declare the class as conforming to the protocol.
class MyClass: SFSafariViewControllerDelegate {
}
Implement the delegate method to be notified on dismissal.
func safariViewControllerDidFinish(controller: SFSafariViewController) {
// Dismiss the SafariViewController when done
controller.dismissViewControllerAnimated(true, completion: nil)
}
Don’t forget to set your class as the SafariViewController’s delegate.
let safariVC = SFSafariViewController(URL: yourURL)
safariVC.delegate = self
Additional delegate methods, in Swift 3 form:
// Called when the initial URL load is complete.
func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { }
// Called when the user taps an Action button.
func safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] { }
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents