NSTimer not firing when runloop is blocked

bbum’s answer provides a better way to design your application, but if you want your timer to fire regardless of whether the user is manipulating the UI or not you’ll need to add it to the tracking mode of the runloop.

Assuming that you’re developing for the iPhone, that mode is UITrackingRunLoopMode. If you’re developing for the Mac there is a similarly named NSEventTrackingRunLoopMode.

NSRunLoop *runloop = [NSRunLoop currentRunLoop];
NSTimer *timer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(myTimerAction:) userInfo:nil repeats:YES];
[runloop addTimer:timer forMode:NSRunLoopCommonModes];
[runloop addTimer:timer forMode:UITrackingRunLoopMode];

Leave a Comment