Boaz Frenkel
Boaz Frenkel

Reputation: 746

iOS -WKWebView - load content from local host directory/files (.js and assets)

I want to run a local HTML file in a WKWebView. Then I want to use some local files (.js and assets) from a local directory located in the app bundle or from a path in the app documents directory Then serve them on my localHost. It looks like I have an issue loading files from the local directory.

I Create a local web server with a specific port (8090) with: GCDWebServer Here is the initial file I'm loading to the WKWebView (which is loaded):

<script type="text/javascript" src="http://localhost:8090/PATH_TO_FOLDER_WITH_ASSETES_TO_FILE_AND_FILE_NAME.js></script>
        <script>
            function loadContent() {
                var config = {
                    Id: "someID",
                    staticServer: "http://localhost:8090/PATH_TO_FOLDER_WITH_ASSETES/",
                    remoteServer: "https://myApp-staging.io/",
                    language:"en"
                };
                var success = function (new) {};
                var error = function (error) {};
                nert(config, success, error);
            }
        window.addEventListener("load", load);
            </script>
    </head>
    <body><div id="content"></div></body>
</html>

Result: I'm getting 501 error when trying to get the files

Upvotes: 1

Views: 514

Answers (1)

Dani
Dani

Reputation: 187

The problem might rely on GCDWebServer, you need to configure the server specifying that PATH_TO_FOLDER_WITH_ASSETS is gonna serve static files , otherwise it will think you want to call a method in the api, that's why you're getting a 501 error.

Upvotes: 0

Related Questions