From c39011539f727f295e8269ed9874838961ccf1a7 Mon Sep 17 00:00:00 2001 From: Fernando Valverde Date: Thu, 5 Nov 2020 10:40:59 -0600 Subject: [PATCH] Example project tweaks --- Example/ViewController.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 124eca7..ee55b5f 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -16,17 +16,19 @@ class ViewController: UIViewController { webView.foremWebViewDelegate = self webView.load("https://dev.to") activityIndicator.startAnimating() + + // Observations need to be retained in order for them to work observations = [ - webView.observe(\ForemWebView.userData, options: .new, changeHandler: { (webView, _) in + webView.observe(\ForemWebView.userData, options: .new) { (webView, _) in if let userData = webView.userData { print("UserID [config_body_class]: \(userData.userID) [\(userData.configBodyClass)]") } else { print("User Logged out") } - }), - webView.observe(\ForemWebView.estimatedProgress, options: .new, changeHandler: { (webView, _) in + }, + webView.observe(\ForemWebView.estimatedProgress, options: .new) { (webView, _) in self.progressView.progress = Float(webView.estimatedProgress) - }) + } ] } } @@ -41,12 +43,13 @@ extension ViewController: ForemWebViewDelegate { } func requestedExternalSite(url: URL) { - print("This was the external site requested: \(url.absoluteString)") // You can open a custom WKWebView for external sites, present SFSafariViewController, etc. + print("This was the external site requested: \(url.absoluteString)") } func requestedMailto(url: URL) { if UIApplication.shared.canOpenURL(url) { + // Should open the default Mail app UIApplication.shared.open(url, options: [:], completionHandler: nil) } } @@ -54,10 +57,11 @@ extension ViewController: ForemWebViewDelegate { func didStartNavigation() { activityIndicator.isHidden = false progressView.progress = 0 + progressView.isHidden = false } func didFinishNavigation() { activityIndicator.isHidden = true - progressView.progress = 0 + progressView.isHidden = true } }