title: NSTimer behavior on background/foreground
body: <p>Scenario is:</p>
  
  <p>Application has on main run loop that runs every 5 min. When app is backgrounded, the timer is not invalidated.</p>
  
  <p>On foreground after waiting a bit (say 10 min), the timer immediately fires twice. I'm unclear as to what the defined behavior here should be (if any) other than on background, the timer is paused/suspended along with the app.</p>
  
  <p>It seems to me that when the app is foregrounded, the timer actually looks at the elapsed time since background, determines the number of times it should have fired in between, and fires them all. I observed this scenario happening both on iOS 7 simulator and iOS 7 iphone.</p>
  
  <p>Google search didn't turn up much info on this topic. Any ideas/pointers?</p>
  
  <p><strong>Update:</strong> Clarification - my question is what is the behavior for NSTimer when the application is backgrounded and then foregrounded again, assuming the timer is not invalidated/nil-ed on background, and a new timer is not created on foreground.</p>
  
  <p>Code sample (code is bit old - pre ARC days):</p>
  
  <pre><code>@implementation ReportHandler {
      NSTimer *_reportTimer;
  }
  
  - (id)init
  {
      if (_reportTimer == nil) {
          _reportTimer = [[NSTimer  timerWithTimeInterval:5*60 target:self selector:@selector(didFireReportTimer:) userInfo:nil repeats:YES] retain];
          [[NSRunLoop mainRunLoop] addTimer:_reportTimer forMode:NSDefaultRunLoopMode];
      }
  }
  
  - (void)didFireReportTimer:(NSTimer *)timer {
     // send report over network here, timer is not invalidated here
  }
  </code></pre>
  
  <p>There are no background/foreground handlers either here or in the app delegate dealing with this timer.</p>