Allow unverified ssl certificates in WKWebView

This is fixed in iOS 9! WKWebView finally makes calls to webView(_:didReceiveAuthenticationChallenge:completionHandler:) on WKNavigationDelegate. Unfortunately this does not work if you run code built in Xcode 7 on iOS 8 devices (at least not in my initial testing). In my example below, I’m not actually doing anything with the cert and just letting it pass … Read more

WKWebView Persistent Storage of Cookies

This is actually a tough one because there’s a) some bug that’s still not solved by Apple (I think) and b) depends on what cookies you want, I think. I wasn’t able to test this now, but I can give you some pointers: Getting cookies from NSHTTPCookieStorage.sharedHTTPCookieStorage(). This one seems buggy, apparently the cookies aren’t … Read more

In Xcode 14 & iOS 16 purple warnings starting with ‘This method should not be called on the main thread as it may lead to UI unresponsiveness.’

Good in-depth reply from an Apple employee on the forums. The poor interaction between WKWebView, Security framework, and this Xcode feature is a known issue (r. 94019453). We plan to address it at some point but I don’t have any info to share as to when that’ll happen.

WKWebView and NSURLProtocol not working

Updated answer for iOS 11 and macOS 10.13 Since iOS 11 it is possible to declare an object that conforms to the WKURLSchemeHandler protocol and register it in the WKWebView configuration: -[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:]. Old answer WKWebView makes requests and renders content out-of-process, meaning your app does not hear the requests they make. If you are … Read more

How to delete WKWebview cookies

Apple released new APIs for iOS 9 and newer versions, so now we can remove domain-specific cookies stored for WKWebView with the below code. Swift 4/5 version: let dataStore = WKWebsiteDataStore.default() dataStore.fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in dataStore.removeData( ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), for: records.filter { $0.displayName.contains(“facebook”) }, completionHandler: completion ) } Below is the Swift 3 version let … Read more

WKWebView Content loaded function never get called

You are not setting the navigationDelegate. Set it and it should be fine. class ViewController: UIViewController, WKNavigationDelegate { override func viewDidLoad() { super.viewDidLoad() let noLayoutFormatOptions = NSLayoutFormatOptions(rawValue: 0) let webView = WKWebView(frame: CGRectZero, configuration: WKWebViewConfiguration()) webView.setTranslatesAutoresizingMaskIntoConstraints(false) webView.navigationDelegate = self view.addSubview(webView) view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(“V:|[webView]|”, options: noLayoutFormatOptions, metrics: nil, views: [“webView”: webView])) view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(“H:|[webView]|”, options: noLayoutFormatOptions, metrics: nil, views: [“webView”: … Read more

Insert CSS into loaded HTML in UIWebView / WKWebView

You can do it like this: – (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *cssString = @”body { font-family: Helvetica; font-size: 50px }”; // 1 NSString *javascriptString = @”var style = document.createElement(‘style’); style.innerHTML = “https://stackoverflow.com/questions/33123093/%@”; document.head.appendChild(style)”; // 2 NSString *javascriptWithCSSString = [NSString stringWithFormat:javascriptString, cssString]; // 3 [webView stringByEvaluatingJavaScriptFromString:javascriptWithCSSString]; // 4 } What this code does: // 1 : … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)