Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Last active February 28, 2017 16:23
Show Gist options
  • Save saoudrizwan/12d57c054892c5e82d8db205ec5c1c17 to your computer and use it in GitHub Desktop.
Save saoudrizwan/12d57c054892c5e82d8db205ec5c1c17 to your computer and use it in GitHub Desktop.
Helper method to open a safari view in app. Don't forget to import the SafariServices framework in 'Project' > 'Linked Frameworks'.
import SafariServices
var safariViewController: SFSafariViewController?
extension ViewController: SFSafariViewControllerDelegate {
func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
if !didLoadSuccessfully {
// check if online
print("couldn't open safari view")
}
}
func presentSafari(withLink link: URL, completion: @escaping () -> Void) {
self.safariViewController = SFSafariViewController(url: link)
self.safariViewController?.delegate = self
guard let webViewController = self.safariViewController else { return }
self.present(webViewController, animated: true, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment