views:

42

answers:

2

I have an app which uses a UIWebView to load a webpage, I then parse the links (triggered by a call of webViewDidFinishLoad) from that webpage and load all these html files using NSString initWithContentsOfURL. This works, but it takes forever to load the links... even tho I've clocked how long each initWithContentsOfURL call takes and they are reasonable (mostly in the range of 0.2s per page). Is it possible that UIWebView is interfering with this somehow, maybe it is causing the thread to block? Also, I have noticed that webViewDidFinishLoad is called multiple times, is there a reason why the UIWebView would be loading multiple times?

James

A: 

initWtihContentsOfURL blocks the thread that its being called on so if it's done on the main thread as I assume you are doing 1)Only one will happen at a time so if there are 10 links it would in theory take 2 seconds to complete and 2)block the UI of the App so there would be no user feedback during that time.

Take a look at NSURLConnection to run it as a separate thread or take a look at NSOperationQueue to do it another way.

As far as webViewDidFinishLoad being called multiple times I think more information is needed about ur app logic to give a good answer

Rudiger
A: 

I figured I would recommend ASIHTTPRequest, which supports asynchronous requests.

Jorge Israel Peña