I have looking for a way to set a proxy to WKWebview request with no luck.
By another hand I have been able to set proxy to http request
func createURLSessionConfiguration(_ host:String,_ port:String) -> URLSessionConfiguration {
let config = URLSessionConfiguration.default
config.requestCachePolicy = URLRequest.CachePolicy.reloadIgnoringLocalCacheData
config.connectionProxyDictionary = [AnyHashable: Any]()
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPEnable as String] = 1
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPSProxy as String] = host
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPSPort as String] = port
return config
}
But my question to you guys is how can set the proxy to the WKWebView?
I'll really appreciate your help
Unlike UIWebView, which does not support server authentication challenges, WKWebView does. In practical terms, this means that when using WKWebView, you can enter site credentials for password-protected websites.
A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.
You can implement WKWebView in Objective-C, here is simple example to initiate a WKWebView : WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; WKWebView *webView = [[WKWebView alloc] initWithFrame:self. view. frame configuration:theConfiguration]; webView.
WKWebView. WKWebView was introduced in iOS 8 allowing app developers to implement a web browsing interface similar to that of mobile Safari. This is due, in part, to the fact that WKWebView uses the Nitro Javascript engine, the same engine used by mobile Safari.
HTTP proxying is not possible with WKWebView -- the NSURLProtocol registering trick doesn't work when using WKWebView (it works only with UIWebView).
A similar trick might have been possible using WKURLSchemeHandler, but it doesn't allow registering schemes that are natively handled by WKWebView, so it isn't really possible.
Source: https://forums.developer.apple.com/thread/110312#337642
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With