Thursday, June 10, 2010

iOS Multitasking and Background Updating

Marco Arment describes the limitations of iOS4 multitasking and why iOS 4 won't allow his popular iPhone/iPad app Instapaper to run in the background and periodically fetch content.

Here's his proposed solution:

Proposed solution: A new multitasking type

The addition of one more multitasking service would solve this issue for a lot of application types: a periodic network request. Here’s how I would do it:

  • The application gives the system an NSURLRequest and an ideal refresh interval, such as every 30 minutes, every few hours, or every day.

  • iOS executes that request, whenever it deems that it should, and saves the response to a local file.

  • Next time the application launches, iOS hands it an NSData of the most recent response.

Executing the request “whenever it deems that it should” is important. iOS can decide, for instance:

  • Not to update when the battery is low, connectivity is poor, other requests are running, free memory is low, CPU usage is high, or the user is predicted to exceed their monthly data limit.
  • Not to update as frequently as the app requests, or to increase the interval over time, or to dynamically adjust the interval based on how often it receives a 304 (Not Modified) response.
  • Not to update at all if the requesting app has not been launched in a long time.

No comments:


Related Posts Plugin for WordPress, Blogger...