title: Correct way to poll server in background
body: <p>Assuming this is possible, I would like my iOS application, when backgrounded, to poll a server (i.e. essentially, retrieve the contents of a URL every 30 minutes and notify the user if it contains something "interesting"), essentially in a similar way to the way the built-in mail client assumedly works if you're not using push notifications.</p>
  
  <p>Now, from my reading so far (I'm an experienced programmer, but new to iOS), I think there may be two potential ways to do this:</p>
  
  <ul>
  <li>Method 1: In applicationDidEnterBackground:, start a background task which does the periodic polling;</li>
  <li>Method 2: Send your own app a UILocalNotification with no visible text to the user, but which simply serves to wake your app up in X minutes time to do the polling (and then send itself another notification for next tim etc).</li>
  </ul>
  
  <p>I see in Apple's documentation of <a href="http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html" rel="noreferrer">Scheduling, Registering, and Handling Notifications</a>, they actually seem to have an example usign Method 1 (their "chat" example, Listing 2-2). But what is surprising about this method is that it appears to just sit in a continual loop doing the polling, with no intervening sleep; on platforms I'm more familiar with, this would be inadvisable and would burn CPU.</p>
  
  <p>So subparts of my question are essentially:
  - Is Method 2 possible (or <em>must</em> a UILocalNotification always cause a visible alert to the user, which is not what I want) and if so is it the recommended way to do this?
  - If the way to do it is Method 1, is Apple's "chat" example of sitting in a continual loop actually OK (e.g. does iOS ration the CPU so that this isn't an issue), and if not what is the way in iOS to tell the background process to "sleep for X seconds/minutes"? And if Apple's continuous loop is OK for whatever reason, what would then be the way to time the intervals between polling?</p>
  
  <p>N.B. I appreciate that being able to run in the background at all is essentially an iOS 4 feature. I don't mind if my app will only run in iOS 4.</p>