views:

79

answers:

3

I have a bunch of media that I need to display in a UIWebView on the iPhone. I would prefer if the client did not have to download said media on booting up the application, but could just reference it locally and download it during the install of the application.

Is this possible?

A: 

No, it's not possible. What you can do is put a default media set in your Resources folder and when the application runs for the first time copy that information to the data folder.

On subsequent runs, you can overwrite that information with fresh one from your server.

pgb
Which data folder?
DevDevDev
A: 
UIWebView * view = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)]; 
NSMutableString * html = [[NSMutableString alloc] init];

NSString * imgpath =  [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
[html appendFormat:@"<html><body><img src=%@/></body></html>", @"test.png"];

NSURL * url = [[NSURL alloc] initFileURLWithPath:imgpath];

[view loadHTMLString:html baseURL:url];


yes, you can use images from within your bundle.

CiNN
Just shove everything in Safari's cache? On application load transfer all the media there?
DevDevDev
A: 

I would think that the loadHTMLString:baseURL: method would do the trick.

From http://iphoneincubator.com/blog/windows-views/uiwebview-revisited, the code would look something like this:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];

You'd have to adjust the path to point to the local documents folder rather than the bundle folder if you'd like the content to be dynamic.

jenningj
I'm referencing it from the browser, not the iPhone
DevDevDev