Monday, April 29, 2013

NSBundle resourceURL example ios


resourceURL

Returns the file URL of the receiver's subdirectory containing resource files.
- (NSURL *)resourceURL
Return Value
The file URL of the receiver's subdirectory containing resource files.
Discussion of [NSBundle resourceURL]
This method returns the appropriate path for modern application and framework bundles. This method may not return a path for non-standard bundle formats or for some older bundle formats.
Example of [NSBundle resourceURL]
NSString *pathForImage = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
NSURL *URL = [NSURL fileURLWithPath:pathForImage];
If you're loading an HTML file that references the images (such as by including an <img src="image.png">, with no path info) then:
[webView loadHTMLString:htmlString
    baseURL:[[NSBundle mainBundle] resourceURL]];
EDIT: so, supposing you had image.png in your application bundle as a resource, then you could do:
[webView loadHTMLString:@"<html><body><img src=\"image.png\"></body></html>"
    baseURL:[[NSBundle mainBundle] resourceURL]];