title: When the device goes to sleep, which ios versions call applicationWillResignActive and which call applicationDidEnterBackground?
body: <p>I have determined experimentally using a couple devices that (as far as I can tell) iOS devices running iOS 4 call applicationWillResignActive when they go to sleep (either when the user presses the top right button, or when the screen shuts off due to inactivity, but the app is still running), but devices running iOS 5 call applicationDidEnterBackground when this happens, and only call applicationWillResignActive for something like an incoming text message/phone call, or the user pulling down the notification bar (in other words, very temporary events).</p>
  
  <p>The iOS device going to sleep, however, is not a very short event (could be a very long one) and thus for that case I'd like to cancel the current server call, which I don't need to do (and don't want to do) for very short interruptions.</p>
  
  <p>My question is: is there a way to tell when the app has gone to sleep as opposed to any other shorter interruption (ie text message), and/or, alternatively, does anyone know if my guess above about what iOS 4 vs 5 devices call when they go to sleep is indeed correct?</p>
  
  <p>This is what I have right now, in applicationWillResignActive:</p>
  
  <pre><code>    if ([[[UIDevice currentDevice]systemVersion] hasPrefix:@"4"] ) { 
          //cancel server call
      }
  </code></pre>
  
  <p>This works fine as far as I can tell, but every thread I've read about how to determine iOS version on the device says that you shouldn't use that code if possible, and should instead call the correct selector for what you're trying to do.  But I've no idea what that would be in this case.</p>