Marco Arment on iPhone Multitasking:
One of my most common feature requests is for Instapaper to periodically download articles in the background. A lot of people forget to launch the app to let it download content before going underground or boarding a plane.
I’ve already received multiple emails from people who are excited for iOS 4’s multitasking because they can’t wait for this to finally stop being an issue, because they think Instapaper will be able to download articles periodically in the background.
It’s painful to respond, crushing their hopes, to tell them that the iOS multitasking system doesn’t allow me to do that.
The solution he proposes:
- 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.
It's an improvement, although it doesn't go far enough for me. There's a couple of enhancements I'd love to see.
If the user isn't actively using the phone when the data is retrieved, it would be great if the application were given a chance to process that information, and possibly notify the user (even if this requires user opt-in).
For instance, if you've got a stock application and it periodically retrieves the prices of the equities within your portfolio, it would be nice if it could be set to notify you when prices cross certain thresholds, or change dramatically, rather than having to launch the application before it's given a chance to process the data.
The polling model will do, but since the iPhone already supports push notifications, it seems like supporting push notifications whose target is an application rather than the user would also be handy. Instead of having your stock application download regular price updates, the server-side element could watch stock prices, looking for price changes of enough difference to matter, then push those prices to your application.
As with the rest of Marco's solution, I think it's reasonable to give iOS some decision-making authority with respect to when and how these things are processed. I don't expect the phone to run out making regular requests to the server or sending lots of push notifications and firing up applications when the battery's already low.
The Future of iPhone Multitasking
I suspect Apple has already considered approaches like what Marco has proposed and the enhancements I'm suggesting here. I also suspect that they've decided explicitly not to take these approaches for the time being.
I can live with that. They're expanding on multitasking for iOS4, and applications will take some time to catch up. Once developers, consumers and Apple have had the chance to take iOS 4 multitasking in hand, there will be a chance to expand upon that further, and I think the proposal offered by Marco and the enhancements I'm suggesting here are good examples of the directions they can take while still taking a cautious approach to multi-tasking in iOS.