Is it possible to read the contents of a web page into a string so i can parse out the data?

前端 未结 2 1005
长发绾君心
长发绾君心 2021-01-23 13:22

I\'d like to be able to get my iphone to load a URL( or really the file that the url points to) into a string. The reason I want to be able to do this is so that I can then pars

2条回答
  •  孤独总比滥情好
    2021-01-23 14:05

    I appreciate that this has been asked and answered, but I would strongly suggest that you consider not using NSString's stringWithContentsOfURL:encoding:error: method for this. If there's one message Apple has tried to send to iOS developers over the past year it is this: Do not make synchronous network calls on the main thread.

    If that request takes more than twenty seconds to respond, which is not at all unlikely with a 3G or EDGE connection, and certainly possible on a WiFi connection, iOS will kill your app. More importantly, if it takes more than about half a second to return you're going to anger your users as they fiddle with their unresponsive phones.

    NSURLConnection is not terribly difficult to use, and will allow your device to continue responding to events while it's downloading content.

提交回复
热议问题