2 Replies
      Latest reply on Apr 24, 2019 9:43 PM by Tim9909
      Tim9909 Level 1 Level 1 (5 points)

        I am trying to use an invisible WKWebView to run a (3rd party) javascript API that talks to a server over websockets.  It works fine in the simulator, but will not establish a connection on iOS unless the WKWebView is in the view hierarchy.  Possibly, I can live with that, but it makes me wonder whether this approach is too brittle.  Is this behavior documented anywhere?  What would be a better approach?

        • Re: accessing network from headless WKWebView
          KMT Level 9 Level 9 (14,195 points)

          Simulator runs a stack for macOS. On iOS, without a parent view, you're foregoing the standard APIs that are otherwise needed and help complete the talk-thru necessary for your connection to complete.

           

          And before you ask, I have no idea if those APIs could be sufficiently identified and added to a standalone iOS WKWebView implementation that would survive, etc. Even if they did, it would seem coals-to-newcastle, and much easier to just do it BTB in the first place.

            • Re: accessing network from headless WKWebView
              Tim9909 Level 1 Level 1 (5 points)

              Thanks.  If I had reasonable assurance that it would work as long as it has a parent view, that would be fine.  My concern was whether failure might occur when parent view was not visible or memory was tight.

               

              My alternative is to ditch the node.js library, and talk to the server directly, using JSON-RPC over https or websocket.  That doesn't look too bad for immediate needs.