I am currently writing an app for the iOS platform which communicates to a server through TCP. The problem is: I want to start an NSThread which runs into an infinite loop that checks that my
- (BOOL)connected
still returns true every 10 seconds, once the connect function has returned successful.
How can I make a timer that runs a function and checks its return value every 10 seconds?
Any help is appreciated, thanks in advance.
Why do not you use
NSTimerto run a timer which will run every 10 seconds to check the status of connection?NSTimerreference is given here. There are many static methods to create a timer. You can use for example:You can use it as
where
myobjectwill be an Objective-C object and its method-checkConnectionStatusor which method you like will check the status of the connection.