开发者

call function after defined seconds without using timer

开发者 https://www.devze.com 2023-03-25 09:01 出处:网络
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.

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 rep开发者_高级运维eats:YES];

}

Thanks in advance


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号