@interface
NSTimer *autoTimer;
@implementation
// Start timer
autoTimer = [NSTimer scheduledTimerWithTimeInterval:(3.0)
target:self
selector:@selector(autoTimerFired:)
userInfo:nil
repeats:YES];
// Stop timer:
[autoTimer invalidate];
autoTimer = nil;
First, you want to keep a pointer to the timer
self.packetTimer = [NSTimer timerWithTimeInterval:CONNECTION_TIMEOUT target:self selector:@selector(connectionTimeout:) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:packetTimer forMode:NSDefaultRunLoopMode];
If somewhere else in your code you want to cancel it, just call:
[self.packetTimer invalidate];
self.packetTimer = nil;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With