How to add Timer to loop
how to add timer to loop. i am making a ur开发者_JAVA百科lConnection 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.
NSURLConnection
has a method - (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode
. Is this what you're looking for?
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.
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.
精彩评论