Im running into an issue where my timer is randomly not working. I can literally STOP the app and rebuild it without changing any code. It works sometimes, and sometimes does not?
When I say “sometimes” I am talking about per app session. If it starts up, it will remain running. But it is not running every app session.
I am seeing the same thing when using both code blocks below.
//Code1:
//I tried this block of code after reading it might be related to how I am interacting with my UIElements while the timer is running in the background.
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
syncWithServerTimer = [NSTimer timerWithTimeInterval:15 target:self selector:@selector(syncWithServer) userInfo:nil repeats:YES];
[runloop addTimer:syncWithServerTimer forMode:NSRunLoopCommonModes];
[runloop addTimer:syncWithServerTimer forMode:UITrackingRunLoopMode];
//Code2:
syncWithServerTimer = [[NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(syncWithServer) userInfo:nil repeats:YES] retain];
Again, I tried both of these and they both work MOST of the time, but not ALL of the time.
What might be the issue? I am not prematurely releasing or invalidating.
So I guess its best to fire your timers on your Main Thread!
Seems to work everytime I do it now.