Reputation: 3049
I'm trying to download, save and show again an image. I'v manage to downolad it and store it to documents directory. So now if i go there with finder i can see those images. Now i'm trying to load it into web view. For that i use these code:
[webview loadHTMLString:simpleHtml baseURL:nil];
In my simple html i have:
<html><head></head><body>
<img src='/Users/user/Library/Application Support/iPhone Simulator/5.1/Applications/45584ECD-021A-4789-8936-6A0012242380/Documents/image.png' />
</body></html>
It loads but it shows a question mark, like if there were no image at that directory.(The image is there because i can find it in finder...)
btw simpleHtml is a NSString not folder...
Upvotes: 0
Views: 1528
Reputation: 3049
i finally get it to work, however it dons't work with html. I use image data now.
NSData *imageData = [NSData dataWithContentsOfFile:image];
[webview loadData:imageData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
Now i find out another solution even better: To my original html string i need to ad prefix file:. So i have now:
<img src="file:/path">
And it works like a charm!
Upvotes: 1
Reputation: 183
you can check this it will be help you.
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];
You can then refer to your images like this:
or you can refer this link:
http://iphoneincubator.com/blog/windows-views/uiwebview-revisited
Upvotes: 2
Reputation: 4249
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *ImagePath = [documentsDirectory stringByAppendingPathComponent:@"yourimage.png"];
Use the above "ImagePath" in your html string.Instead of using 'loadHTMLString' use the following method of webview
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:imagePath]]];
Upvotes: 1