You should implement SFSafariViewControllerDelegate
so that your class is notified when the user hits the Done button on the SafariViewController and you can dismiss it as well.
First declare your class to implement 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 you can implement are:
// 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] { }