Intercept request with WKWebView

前端 未结 6 595
遇见更好的自我
遇见更好的自我 2021-02-04 05:32

Now i\'m using UIWebView and with canInitWithRequest: of NSURLProtocol i can intercept all requests and do with it what I want.

In

6条回答
  •  情歌与酒
    2021-02-04 06:24

    One can use WKURLSchemeHandler to intercept each and every request to be loaded in WKWebView, Only disadvantage is that you cannot register http or https scheme for interception,

    Solution over that is, Replace your http/https scheme of url with custom scheme url like xyz:// for e.g. https://google.com can be loaded like xyz://google.com Now you will get a callback in WKURLSchemeHandler there you again replace it back to https and load data programmatically and call urlSchemeTask.didReceive(response)

    This way each and every https request will come to your handler.

提交回复
热议问题