3 Replies
      Latest reply: Dec 28, 2016 3:32 PM by eskimo RSS
      BalanPrabhu Level 1 Level 1 (0 points)


        How to provide custom response for my network requests in WKWebView?


        I know it is possible in UIWebView using NSURLProtocol, but not with WKWebView. So is there any alternative in WKWebView to achieve this?

        • Re: NSURLProtocol in WKWebView
          eskimo Apple Staff Apple Staff (6,075 points)

          WKWebView does all of its networking out of process, which means it does not ‘see’ your NSURLProtocol subclass.

          What’s the goạl of your NSURLProtocol here?  The NSURLProtocol-under-UIWebView thing was always a bit of a hack, and in many cases WKWebView provides better techniques with real APIs.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: NSURLProtocol in WKWebView
              da_gagnon Level 1 Level 1 (0 points)

              Hi,

               

              We are trying to port our Cordova app to WKWebView. But the Cordova File plug-in use a custom scheme to work. With UIWebView, this plug-in was intercepting URLs with custom scheme using NSURLProtocol to load related files (local resources files). It seem that it is not possible to do that with WKWebView, and it is a blocker for us.


              There is another strategy to do that in WKWebView?

              Do we need to wait iOS 11 to have this kind of feature?

               

              Thanks!

                • Re: NSURLProtocol in WKWebView
                  eskimo Apple Staff Apple Staff (6,075 points)

                  There is another strategy to do that in WKWebView?

                  That depends on how you load the resources.  If you’re in control of the JavaScript code that loads the resources, you can take advantage of WKWebView nice JavaScript/native integration points.  However, if the resources are loaded by the web view itself, you really need an NSURLProtocol and that’s hard to avoid.

                  Do we need to wait iOS 11 to have this kind of feature?

                  You can certainly file an enhancement request for the features you need.  However, if you were in your shoes I’d discuss this with the Cordova folks; it seems like they should have a strategy for dealing with the reality of WKWebView.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"