WKWebView question

Hello,


I'm trying to migrate to WKWebView.

Currenly my project uses UIWebView.

The problem is that all my resources are encrypted, by utilizing the URLProtocol i can decrypt all the requested resources on the fly.


As the WKWebView is not using URLProtocol, i still need to substitute the requested resources with decrypted ones.

Is there any way to handle this for WKWebView?


Thanks in advance.

Replies

Is there any way to handle this for WKWebView?

Not easily.

What sort of resources are you talking about?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hello,

It cloud be a JS/PNG/JPEG/HTML files as well as some custom fonts, css etc..
My app is some kind of a container, which downloads some html/js/images etc... files.
I'm not controlling the content. Also, i have protection keys which are store in DB per each encrypted file.

Some of these files are encrypted some of them not.

Don't know the reason, this comes from the client request.
So for UIWebView + URLProtocol it works perfect. Tried with WKWebView, but can't find a way to do the same as for UIWebView.

Some years ago, i'm using NSURLCache instead of NSURLProcol, but this stops working for "FILE" url scheme after some iOS version update.

Not sure, if NSURLCache can be used here.


Thanks in advance.

It cloud be a JS/PNG/JPEG/HTML files as well as some custom fonts, css etc … I'm not controlling the content.

OK. Alas, there’s no way to make this work for WKWebView. The reason this works for UIWebView is that UIWebView runs entirely within your process and does its network requests with NSURLSession. NSURLSession consults NSURLProtocol subclasses, so you can insert yourself into the loading process.

In contrast, the bulk of WKWebView, and specifically the code making its network requests, runs outside of your process, and thus does not see your NSURLProtocol subclass.

As things currently stand you’ll have to stick with UIWebView. If you'd like to see WKWebView support this sort of thing in the future, I encourage you to file an enhancement request describing your requirements. Please post your bug number, just for the record.

Not sure, if NSURLCache can be used here.

NSURLCache will definitely not help here; like NSURLProtocol, it’s only consulted by network requests run in your process.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo, now WKWebview has any solution to this?

now

WKWebview
has any solution to this?

It depends on your specific requirements. In some situations you can do this using the

WKURLSchemeTask
feature we added in iOS 11. The main drawback with this approach is that you can’t override the built-in URL schemes, so you have to switch your entire site over to using a custom URL scheme. If you can do that, you’re golden. If not, things get trickier.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"