views:

85

answers:

3

how to add timer to loop. i am making a urlConnection so i want that the loop execute for a time and if there is no connection it should exit.

Does it work.....

[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1f]];

Thanks in advance.

A: 

NSURLConnection has a method - (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode. Is this what you're looking for?

Jasarien
hi jasarien.. actually i don't have any idea....i want end timer after perticular time ..can u send me the syntax of that perticular method
mukeshpawar
A: 

Sounds like you want @selector(timerWithTimeInterval:target:selector:userInfo:repeats:).

"Returns a new NSTimer that, when added to a run loop, will fire after a specified number of seconds." See http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

Set repeats:YES and invalidate the timer after your timeout value is reached.

Zack
thank you Zack for this infomation.
mukeshpawar
A: 

If you are trying to make your url connection attempt time out after a certain interval, you would be far better off looking at the timeout value on NSURLRequest. Synchronous connections should be avoided wherever possible.

Paul Lynch