Intercept WKWebView requests and responses in iOS 9

270 Views Asked by At

I have the following requirements:

  • The application has local HTML content that is encrypted
  • This local content has to be displayed using a WKWebView
  • Intercept the requests done from the WKWebView and provide a custom response for each requests (decrypting the content on the fly)
  • Support iOS 9.3

The requirements could be fulfilled using WKURLSchemeHandler but this was only introduced in iOS 11.

The only solution that I can reach so far would be:

  • Embed a web server in the application listening for example at http://localhost:8080
  • The server would read the local content, decrypt it and send it back to the WKWebView
  • Change the web content so that all requests are directed to http://localhost.8080

Having an embeded web server seems overkill and will introduce a whole lot of trobule. But it seems this is the approach that has been taken when faced with similar requirements. For example the Cordova and Ionic Capacitor projects.

Ionic Capacitor only removed the embeded web server when they dropped support for iOS 10: https://github.com/ionic-team/capacitor/releases/tag/1.0.0-beta.11

I'm not interested in solutions using private APIs.

0

There are 0 best solutions below