views:

34

answers:

2

In previous apps, I've loaded data into a UIWebView using 4 steps: 1. Use an NSURL Connection to grab the data from the web asynchronously 2. WHen the download is complete, convert the NSData object to a string, and manipulate the data prior to display. 3. Write the converted data out to the doc folder 4. Load the data into the UIWebView from the file

But in my current app, I have no need to manipulate the data that I load from the web. I simply want to download asynchronously, and load it into a UIWebView while that view is not yet visible. Then show that view later, when I need it.

Would it be better to use a loadRequest message that was dispatched as a block to GCD? Is that workable? I'm trying to avoid the whole mess of writing to a local file, then reloading the page from that file. Suggestions?

+2  A: 

Why not just give the NSURLRequest directly to the webview? It's perfectly capable of loading data from the web itself if you don't need to massage the data in transit.

Kevin Ballard
Insn't that a synchronous request, if done using loadRequest? So my main run loop will be tied up while this data is fetched from the URL.
Don Wilson
Nope, WebView always loads stuff asynchronously. It's only synchronous if you use NSURLConnection to load a synchronous request.
Kevin Ballard
+2  A: 

Try like this

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];

All the best.

Warrior