From 81c8d7494208e8da64ec1b2b848ab56ed3bca26e Mon Sep 17 00:00:00 2001 From: Ivan Magda Date: Tue, 13 Feb 2018 11:35:29 +0300 Subject: [PATCH] fix: Resolve WebKitErrorDomain 102 (#3) Ignore WebKitErrorDomain 102 error. --- Tagger/FlickrOAuthViewController.swift | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Tagger/FlickrOAuthViewController.swift b/Tagger/FlickrOAuthViewController.swift index 72e99ac..901d6ae 100644 --- a/Tagger/FlickrOAuthViewController.swift +++ b/Tagger/FlickrOAuthViewController.swift @@ -114,12 +114,23 @@ class FlickrOAuthViewController: UIViewController { extension FlickrOAuthViewController: UIWebViewDelegate { func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { - let callback = NSURL(string: callbackURL)! - if request.URL!.host == callback.host { + guard let url = request.URL else { + return false + } + + if url.host == callbackURL.host { successBlock(URL: request.URL!) dismiss() return false } + + if url.scheme != "http" && url.scheme != "https" { + if UIApplication.sharedApplication().canOpenURL(url) { + UIApplication.sharedApplication().openURL(url) + return false + } + } + return true } @@ -132,6 +143,16 @@ extension FlickrOAuthViewController: UIWebViewDelegate { } func webView(webView: UIWebView, didFailLoadWithError error: NSError?) { + // Ignore NSURLErrorDomain error -999. + if (error?.code == NSURLErrorCancelled) { + return + } + + // Ignore "Fame Load Interrupted" errors. Seen after app store links. + if (error?.code == 102 && error?.domain == "WebKitErrorDomain") { + return + } + guard let error = error else { let error = NSError(domain: "\(BaseErrorDomain).FlickrOAuthViewController", code: 66,