You can specify the URL for this image using the absolute path using the file:// scheme:
NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES)[0]; NSString *filePath = [NSString stringWithFormat:@"file://%@/image.png", documentsDirectory];
Then you can run some javascript to update the src tag to update it to a new path:
NSString *javascript = [NSString stringWithFormat:@"var imageElement = document.getElementById('localFile'); imageElement.setAttribute('src', '%@');", filePath]; [self.webView stringByEvaluatingJavaScriptFromString:javascript];
In your HTML, the path will look something like this:
<html> <body> <img id="localFile" src="file:///var/mobile/Applications/3D7D43E8-FA5E-4B19-B74C-669F7D1F3093/Documents/image.png" /> </body> </html>
source share