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
NSTimer
to run a timer which will run every 10 seconds to check the status of connection?NSTimer
reference is given here. There are many static methods to create a timer. You can use for example:You can use it as
where
myobject
will be an Objective-C object and its method-checkConnectionStatus
or which method you like will check the status of the connection.