Created
April 6, 2018 14:29
-
-
Save miketsprague/7dcdb1c82f27b71f57b21d4db557d654 to your computer and use it in GitHub Desktop.
RssLoader that uses a webview to parse content. This will work with ATS and `Allow Arbitrary Loads in Web Content` turned on.
This file contains hidden or 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
@objcMembers | |
class RssLoader: NSObject { | |
var completion: ((_ rss: String?)->Void)? | |
var webView: WKWebView! = nil | |
func load(url: URL, completion:((_ rss: String?)->Void)?) { | |
self.webView = WKWebView() | |
let request = URLRequest(url: url) | |
self.completion = completion | |
webView.navigationDelegate = self | |
webView.load(request) | |
} | |
} | |
extension RssLoader: WKNavigationDelegate { | |
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
webView.evaluateJavaScript("document.documentElement.innerHTML.toString()", | |
completionHandler: { (html: Any?, error: Error?) in | |
self.completion?(html as? String) | |
}) | |
} | |
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) { | |
decisionHandler(.allow) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment