Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to clear cache for my UIWebView's loadHtmlString?
    primarykey
    data
    text
    <p>I have some embedded html in my application bundle.I'm using loadHtmlString to load it. At the same time there are some image files in my documents folder.I want to replace my img in html with the one in my documents folder. For example, here is the sample html I have:</p> <pre><code> &lt;div id="image"&gt; &lt;a href="image"&gt; &lt;img src="@image" class="center"&gt; &lt;/a&gt; &lt;/div&gt; </code></pre> <p>I'm using the following code to replace the @image to the file path in my documents:</p> <pre><code> NSString* imgFile = [NSString stringWithFormat:@"file:///%@/%@", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images"],@"myimage.png"]; text = [text stringByReplacingOccurrencesOfString:@"@image" withString:imgFile]; NSURL* baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]; [self.webView loadHTMLString:text baseURL:baseUrl]; </code></pre> <p>(text is the html text of my html file).</p> <p>It works the first time when this code is called. But for example, if I modify myimage.png and call the code again, the image before I modified is still showed. (I have check my file in my document folder, it's already modified correctly).</p> <p>I suspect it's caused by the cache. Can anybody advise?</p> <p>Thanks</p> <p><strong>Note:</strong></p> <p>It is caused by the cache. I solved the problem by using the following method to force UIWebView to load a fresh copy of image:</p> <pre><code>NSString* imgFile = [NSString stringWithFormat:@"file:///%@/%@?t=%d", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images"],@"myimage.png",time(NULL)]; text = [text stringByReplacingOccurrencesOfString:@"@image" withString:imgFile]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload