I have built-in html in my application. I am loading loadHtmlString. At the same time, there are some image files in the folder of my documents. I want to replace my img in html with the one that is in the folder of my documents. For example, here is an example html that I have:
<div id="image"> <a href="image"> <img src="@image" class="center"> </a> </div>
I use the following code to replace @image with the file path in my docs:
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];
(text is the html text of my html file).
It works the first time this code is called. But, for example, if I modify myimage.png and call the code again, the image is still displayed before I change it. (I check my file in the folder of my document, it has already been changed correctly).
I suspect this is due to the cache. Can anyone advise?
thanks
Note:
This is caused by the cache. I solved the problem using the following method to force UIWebView to load a new copy of the image:
NSString* imgFile = [NSString stringWithFormat:@"file:///%@/%@?t=%d", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images"],@"myimage.png",time(NULL)]; text = [text stringByReplacingOccurrencesOfString:@"@image" withString:imgFile];
source share