Problem description
WKWebView is a modern web view from the WebKit framework that displays web content in iOS applications. It replaces the legacy UIWebView and provides better performance, more features, and higher security.
How can you use HTTPDNS for domain name resolution when WKWebView loads web content? Does HTTPDNS support integration with WKWebView on iOS?
Cause
UIWebView is no longer maintained. Applications are switching to WKWebView to load web pages.
Solutions
Apple does not provide hook interfaces for DNS resolution in WKWebView or offer interfaces for custom network request implementations. This is unlike Android, which uses shouldInterceptRequest to intercept GET requests. Because of these limitations, no simple, widely compatible, and risk-free solution exists to integrate HTTPDNS with WKWebView.
If anti-hijacking and precise scheduling are high priorities, and you can invest significant development resources, you can implement the solution as follows:
Use obfuscated private API names to intercept the
httpandhttpsschemes of WKWebView. Then, create a custom network request implementation.In the custom network request logic, use HTTPDNS to handle domain name resolution.
Give special consideration to scenarios such as cookies and large file requests.
EMAS provides an experimental reference solution: EMASCurlWeb. This solution is open source on GitHub. You can use it as a reference to build a complete solution for managing WKWebView network requests that fits your business needs. You can also build on this solution to add features such as resource prefetching and custom caching.
Applicable to
HTTPDNS