Last active
February 28, 2017 16:23
-
-
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'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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