There are two options.
If using timerWithTimeInterval
use the following like.
refreshTimer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(timerHandler) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:refreshTimer forMode:NSRunLoopCommonModes];
also the mode has two options. NSDefaultRunLoopMode vs NSRunLoopCommonModes
Additional Information. refer to this documentation: RunLoopManagement
If scheduledTimerWithTimeInterval used
use the following like.
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerHandler) userInfo:nil repeats:YES];
scheduled timers are automatically added to the run loop.
more information. refer to this documentation: Timer programming topics
Finally
" timerWithTimeInterval " you must remember to add a timer to the run loop you want to add.
Automatically, by default, " scheduledTimerWithTimeInterval " creates a timer that starts in the current loop.
source share