views:

27

answers:

1

Which is the best way to handle request-timeout. I am sending XML request and if I didn't get response in 10 sec I need to stop activity indicator and show alert message.

Which approach is best out of following:

a. NSTimer - To check status of response

b. NSThread - This will run in background to check response

c. Notification class (I never used it)

Thanks

+2  A: 

If you use NSMutableURLRequest then you can give time interval in this

for eg.

NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];     

so no need to use timer or thread

Reena
I am using NSXMLParser to parse XML as: NSURL *xmlURL = [NSURL URLWithString:URL]; rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];... How can add timeout in this. thanks
iPhoneDev