A support library for WKWebView.
- iOS 12.0 later
WKUIDelegatePlus
has standard implements(Present alerts from JavaScript) for WKUIDelegate
.
override public func viewDidLoad() {
super.viewDidLoad()
UIDelegate = WKUIDelegatePlus(self)
webView.UIDelegate = UIDelegate
}
It is funtastic that WKWebView
has key-value observing compliant properties, but KVO is so ugly. WebViewObserver
makes observable it by closure.
lazy var observer: WebViewObserver = WebViewObserver(self.webView)
override public func viewDidLoad() {
super.viewDidLoad()
observer.onTitleChanged = { [weak self] in self?.title = $0 }
observer.onProgressChanged = { [weak self] in self?.progressbar.progress = $0 }
}
Use UIAlertController (for: completion :)
to input informations of authentication.
/// in `WKNavigationDelegate` object
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
guard let alert = UIAlertController(for: challenge, completion: completionHandler) else {
// Should call `completionHandler` if `alertForAuthentication` return `.None`.
completionHandler(.performDefaultHandling, nil)
return
}
present(alert, animated: true, completion: nil)
}
ZenWebViewController
is a Simple View Controller contains WKWebView
. You can implement simple web browser with it.
@yashigani
WebKitPlus is available under the MIT license. See the LICENSE file for more info.