@Frankenstein's answer worked for me, but it took me a while to setup my code correctly, so just want to add some code snippets here
class MyViewController: UIViewController {
func presentSafariVC() {
let url = //...
let config = SFSafariViewController.Configuration()
let safariVC = SFSafariViewController(url: url, configuration: config)
safariVC.modalPresentationStyle = .formSheet
safariVC.delegate = self
safariVC.presentationController?.delegate = self
present(safariVC, animated: true)
}
}
extension MyViewController: SFSafariViewControllerDelegate, UIAdaptivePresentationControllerDelegate {
// click top left "Done" button and dismissed
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
// do your stuff
}
// swipe down and dismissed
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
// do your stuff
}
}
Also, I was originally looking for a way to prevent swipe down to dismiss the presented vc, but it seems setting safariVC.isModalInPresentation = true
has no effect, I can still swipe down to dismiss it. This is observed on XCode 12, iOS 14.2 simulator.