Wayne Lo
Wayne Lo

Reputation: 3719

How to abort iPhone's NSXMLParser wait

When init the NSXLParser as below:

NSXMLParser* xmlParser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlstring]];

if the server is down, it will wait for quite some time before the thread returns. It is really annoying even if I exit the application and restart the application, it will continue to wait with a black screen until it times out.

How to I abort the init? Is there a better way to check whether the server is up before calling the parser? Thanks for helping.

Upvotes: 0

Views: 297

Answers (2)

riverinyo
riverinyo

Reputation: 176

You should use NSURLConnection and its delegates to download to an NSData type. Then you can control the connection properly. From there you can pass the NSData to the NSXMLParser and control it separately. I hope it help you.

Upvotes: 2

Wayne Lo
Wayne Lo

Reputation: 3719

I ended up use a UIWebView to request the URL first. If it finish loading, I will then call the xmlparser to request the same url again. The nice thing about UIWebView request is that it runs on a different thread so the UI does not freeze.

This is not idea; I hate to request the same URL twice. If you have a better suggestion, please help.

Upvotes: 0

Related Questions