Apple’s done a deft job mitigating the disadvantages of true multitasking with iOS 4 by giving devs access to a few intelligently chosen APIs (like background audio) and universal state saving.
That’ll be good enough for most people and most apps without causing a huge drain on battery life or processing power, but unfortunately, the new iOS 4 APIs don’t do anything to address one of the biggest advantages to multitasking: background applications that can update or sync information when they don’t have focus. In other words, when iOS 4 comes around, apps like feed readers, Twitter clients and IM programs will still need to be open the whole time in order to suck in new information from the Internet.
Over at his personal blog, Marco Arment — developer of App Store favorite Instapaper — has posted a great suggestion to Apple on how to allow apps to update themselves in the background efficiently: give iOS the ability to prioritize periodic third-party app network requests.
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.
This would allow Instapaper to download updates in the background, and would also greatly benefit RSS readers, Twitter clients, chat programs, weather and news widgets, and a huge number of other applications that currently can’t get much benefit from iOS’ multitasking.
I’m certainly no system architect, but it sounds like an effective solution to me. In fact, it’s such an understandable and obvious solution that the thought of waiting until the iOS 5 update for such functionality gives me a little case of the shakes… although that could be last night’s Talisker talking.