Does HTTPDNS support WKWebView integration on iOS?

更新时间:
复制 MD 格式

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:

  1. Use obfuscated private API names to intercept the http and https schemes of WKWebView. Then, create a custom network request implementation.

  2. In the custom network request logic, use HTTPDNS to handle domain name resolution.

  3. 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