开发者

question about reading data from urls on iphone/ipad

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 fore开发者_运维百科ver 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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜