0

I have an hybrid app that runs on Android, and uses webView.
In javascript, I make a fetch request call, which is intercepted in webView via shouldInterceptRequest.

I am trying to achieve the same with iOS which uses wkWebView (the language is objective c).
In javascript, I make the same fetch request call, but it is not intercepted in wkWebView.

I added functions based on several links such as this Specifically, I added functions like:

  • createWebViewWithConfiguration
  • decidePolicyForNavigationResponse
  • startURLSchemeTask

For example:

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction preferences:(WKWebpagePreferences *)preferences decisionHandler:(void (^)(WKNavigationActionPolicy, WKWebpagePreferences *))decisionHandler  API_AVAILABLE(ios(13.0)){
...
}

But these functions are never reached, when I call fetch from my javascript code. I read here that wkwebview can intercept xhr request (if not fetch) but this is in swift which I don't understand.

How can iOS intercept fetch requests?

Thanks

p.s. I see posts for this questions and partial explanations that I don't fully understand. A Github example would be helpful but I have not found one so far...

Avner Moshkovitz
  • 856
  • 1
  • 13
  • 24

0 Answers0