Search code examples
iossfsafariviewcontrollersfsafariviewcontrollerdelegate

SafariViewControllerDidFinish does not fire when swiping down to dismiss


I have a delegate on a SFSafariViewController that does clean up tasks in the safariViewControllerDidFinish event. In iOS 13+, the user is able to swipe down to dismiss, but this event is not fired in that case. I do not want to disable this gesture by enabling isModalInPresentation.

Is there a way to make the safariViewControllerDidFinish fire for this case, or how can I detect the user swiping down to dismiss the Safari view controller?


Solution

  • You can know when the user dismisses the SFSafariViewController by swiping down by making yourself the presentation controller's delegate and overriding presentationControllerDidDismiss(_:). Check out the documentation on this topic.

    Note: This method will not get called if you use dismiss(animated:) programmatically.