2
votes

I am calling a function after 180 seconds using timer. But the timer sometimes behaves in different manner and calls the function multiple times in 180 seconds.

please suggest me how to call a function after each 180 seconds untill I post stop message without using timer.

Code

if(!tmr_CallWebService)

{

tmr_CallWebService = [NSTimer scheduledTimerWithTimeInterval:180 target:ClassTracing selector:@selector(startLocationTracing) userInfo:nil repeats:YES];

}

Thanks in advance

2
Can you paste the code where you are creating the timer?Praveen S

2 Answers

3
votes

You can use - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay from NSObject

3
votes

I think there is a method to do this task, here use it like this

[self performSelector:@selector(yourMethodName) withObject:[NSArray arrayWithObjects:firstArgument,secondeArgument,nil] afterDelay:180];

use nil in place of array if you have no argument in that method.