title: UIApplicationWillEnterForegroundNotification received after applicationState != UIApplicationStateBackground test passed
body: <p>I am writing an Objective-C wrapper for using a GCD timer source. One of the goals is for the wrapper to manage suspending the timer source when the application enters the background.</p>
  
  <p>The <a href="http://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40006786-CH3-SW20" rel="nofollow">docs</a> for <code>-[UIApplicationDelegate applicationDidEnterBackground:]</code> indicate that it should be used to invalidate timers, among other things; I'm interpreting this somewhat loosely (perhaps that is the source of my problem?) in that I'm suspending a GCD timer (<code>dispatch_suspend()</code>) in response to <code>UIApplicationDidEnterBackgroundNotification</code>).</p>
  
  <p>When an instance of the wrapper is initialized, it checks <code>[UIApplication sharedApplication].applicationState != UIApplicationStateBackground</code> to determine whether the GCD timer source should initially be resumed as part of the initialization sequence. It also registers for <code>UIApplicationDidEnterBackgroundNotification</code> and <code>UIApplicationWillEnterForegroundNotification</code> which it uses to suspend and resume the timer source (respectively).</p>
  
  <p>The issue that I have observed is that there seem to be cases where the check of <code>[UIApplication sharedApplication].applicationState != UIApplicationStateBackground</code> during initialization is passed so that the timer source is resumed, <strong><em>and</em></strong> the next notification that is received is <code>UIApplicationWillEnterForegroundNotification</code> which causes the timer source to be resumed a second time. This leads to a crash since the timer was not suspended at the time of the second resume.</p>
  
  <p>I can work around this by keeping track of the application state locally and confirming the transitions that would be duplicate, but I am concerned that I may be doing something incorrectly or that there may be a bug (either in implementation or in documentation).</p>