WKWebView function for detecting if the URL has changed

Swift Version // Add observer webView.addObserver(self, forKeyPath: “URL”, options: .new, context: nil) // Observe value override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if let key = change?[NSKeyValueChangeKey.newKey] { print(“observeValue \(key)”) // url value } }

How can i monitor requests on WKWebview?

Finally I solved it Since I don’t have control over the web view content, I injected to the WKWebview a java script that include a jQuery AJAX request listener. When the listener catches a request it sends the native app the request body in the method: webkit.messageHandlers.callbackHandler.postMessage(data); The native app catches the message in a … Read more

Does webKit in iOS 11 (Beta) support WebRTC?

Update: WebRTC Support is coming in iOS14.3 (Beta) 🎉 Learn more here: https://webkit.org/blog/11353/mediarecorder-api/ From iOS11+ : WebRTC is partially supported in WKWebView, and fully supported in the Safari App browser. Explained: WebRTC has three main JavaScript APIs: MediaStream (aka getUserMedia) RTCPeerConnection RTCDataChannel For apps running inside Safari App, iOS11+, all WebRTC APIs are supported. That … Read more

Detect if page is loaded inside WKWebView in JavaScript

The accepted answer doesn’t work as tested using the WKWebView vs UIWebView app As the article mentions, the only HTML5 feature difference is IndexedDB support. So I’d go for a more reliable pattern with: if (navigator.platform.substr(0,2) === ‘iP’){ //iOS (iPhone, iPod or iPad) var lte9 = /constructor/i.test(window.HTMLElement); var nav = window.navigator, ua = nav.userAgent, idb … Read more

ITMS-90809: Deprecated API Usage – existing app that use UIWebView are no longer accepted

Yes, Apple did change the policies Are you using ionic? if so, install these: cordova plugin add cordova-plugin-ionic-webview@latest npm install @ionic-native/ionic-webview Then add this to your config.xml under ios platform: <preference name=”WKWebViewOnly” value=”true” /> <feature name=”CDVWKWebViewEngine”>` <param name=”ios-package” value=”CDVWKWebViewEngine” /> </feature> <preference name=”CordovaWebViewEngine” value=”CDVWKWebViewEngine” /> Finally run ionic cordova prepare ios to reflect the changes … Read more

Disable magnification gesture in WKWebView

You can prevent your users from zooming by setting the delegate of your WKWebKit’s UIScrollView and implementing viewForZooming(in:) as in the following: class MyClass { let webView = WKWebView() init() { super.init() webView.scrollView.delegate = self } deinit() { // Without this, it’ll crash when your MyClass instance is deinit’d webView.scrollView.delegate = nil } } extension … Read more

Saving WebView to PDF returns blank image?

iOS 11.0 and above, Apple has provided following API to capture snapshot of WKWebView. @available(iOS 11.0, *) open func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?, completionHandler: @escaping (UIImage?, Error?) -> Swift.Void) Sample usage: func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { if #available(iOS 11.0, *) { webView.takeSnapshot(with: nil) { (image, error) in //Do your stuff with image } … Read more

How to Migrate to WKWebView?

UIWebView will still continue to work with existing apps. WKWebView is available starting from iOS8, only WKWebView has a Nitro JavaScript engine. To take advantage of this faster JavaScript engine in older apps you have to make code changes to use WKWebView instead of UIWebView. For iOS7 and older, you have to continue to use … Read more

Migrating from UIWebView to WKWebView

UIWebView => WKWebView Equivalent UIWebViewDelegate => WKNavigationDelegate delegate => navigationDelegate didFailLoadWithError => didFailNavigation webViewDidFinishLoad => didFinishNavigation webViewDidStartLoad => didStartProvisionalNavigation shouldStartLoadWithRequest => decidePolicyForNavigationAction About shouldStartLoadWithRequest you can write: func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { print(“webView:\(webView) decidePolicyForNavigationAction:\(navigationAction) decisionHandler:\(decisionHandler)”) switch navigationAction.navigationType { case .linkActivated: if navigationAction.targetFrame == nil { self.webView?.loadRequest(navigationAction.request) } … Read more