I need to start an NSTimer arbitrarily that will repeat every N seconds until I stop it. It's not repeating.
I've tried SO solutions described here, here and here. None of the the accepted answers are working.
Here's what I've done. My UIViewController is calling:
[AppDelegate doStartMessageRefresh];
In AppDelegate.m:
#define MESSAGE_REFRESH_INTERVAL_SECONDS 3.0
@property (nonatomic, retain, strong) NSTimer *messageRefreshTimer;
- (void) doInvokerForDoStartMessageRefresh
{
NSLog(@"%s", __FUNCTION__);
NSLog(@"%@", [self.messageRefreshTimer fireDate]);
}
- (void) doStartMessageRefresh {
NSLog(@"%s", __FUNCTION__);
/*
self.messageRefreshTimer = [NSTimer scheduledTimerWithTimeInterval:MESSAGE_REFRESH_INTERVAL_SECONDS
target:self
selector:@selector(doInvokerForDoStartMessageRefresh)
userInfo:nil
repeats:YES];
*/
self.messageRefreshTimer = [NSTimer timerWithTimeInterval:MESSAGE_REFRESH_INTERVAL_SECONDS
target:self
selector:@selector(doInvokerForDoStartMessageRefresh)
userInfo:Nil
repeats:YES];
// [self.messageRefreshTimer fire];
//[[NSRunLoop currentRunLoop] addTimer:self.messageRefreshTimer forMode:NSRunLoopCommonModes];
[[NSRunLoop currentRunLoop] addTimer:self.messageRefreshTimer forMode:NSDefaultRunLoopMode];
}
The only log line that's printing out is:
2014-05-02 16:34:20.248 myappnamehere[9977:6807] -[AppDelegate doStartMessageRefresh]
If I uncomment the line [self.messageRefreshTimer fire]; it runs once.
If I formulate the selector like: @selector(doInvokerForDoStartMessageRefresh:) and manually fire, I get an unrecognized selector sent