Partho Biswas
Partho Biswas

Reputation: 2330

Intercept and modify resource/url requests while calling loadHTMLString of UIWebView

I am loading some HTML string on UIWebView using loadHTMLString method.

[self.myWebView loadHTMLString:html baseURL:baseURL];

The HTML string looks something like following.

<html>
    <head></head>
    <body>
        <!-- [DocumentBodyStart:9ab3216e-b945-4432-141f-68164c25f0d6] -->
        <div class="jive-rendered-content"> 
            <p class="">Test description</p> 
            <a href="https://a-team-906-test.jivelandia.com/servlet/JiveServlet/previewBody/1091-102-1-1054/IMG_0005.JPG">
                <img src="https://a-team-906-test.jivelandia.com/servlet/JiveServlet/previewBody/1091-102-1-1054/IMG_0005.JPG">
            </a>
        </div>
        <!-- [DocumentBodyEnd:9ab3216e-b945-4432-141f-68164c25f0d6] -->
        <script type="text/javascript" src="web/video-loading-events.js" onerror="alert('cant load video-loading-events.js')"></script>
    </body><br>
</html>

As you can see that there is an Image URL into the HTML content. The issue is that Image doesn't load on the WebView because of authentication issue.

So how can i intercept that image url request to see what's going on under the hood ? And how can i add additional headers with that specific request only, if necessary ?

Objective-C is preferable, but Swift is also welcome. Thanks in advance.

Upvotes: 0

Views: 209

Answers (1)

Matt Tucker
Matt Tucker

Reputation: 71

A good place to start would be to look at using the safari web inspector to see what errors are being logged out to the console when you open the webview in your app.

You will need to enable the web inspector from your iPhone and then make sure you have "Show Develop Menu in Menubar" enabled in safari.

Once both of these are done you can navigate to Develop -> <Your device or simulator> -> <your webview> in safari.

Refresh the page from the developer window and see what gets logged out.

Good luck!

Upvotes: 1

Related Questions