A Proposal for a Deferred Network Request API on iOS

Earlier today, I tweeted about a feature I’d love to see on iOS:

As a subway passenger + iOS developer, it’d be lovely to have API for “Here’s a network request, please send when you can”

After a discussion with Sam Vermette of The Transit App (and fellow NSNorth speaker), I decided it would be a good idea to elaborate more about the idea here.

The basic premise of the idea is, I wish iOS provided an API for applications to submit to the OS a network request (like an HTTP GET or POST) which would be executed by the OS at the next available chance.

This is for times when the device is without internet access, like while riding the subway, but when the user still wants the action to happen. It would tell iOS “When we get network access again, I want you to do this request”, and obviously it should return the response to the application when it does (or on next launch).

An example of this would be using an article posting app on the subway. I might write a nice article on my phone while underground riding the subway, and I press “Post”. Because there is currently no internet access, the app hands off this network request to the OS to be executed at the next available time. I can then safely quit my article posting app, and know that when I get off the subway and my device gets internet access, that my article will finally be posted. When my app launches next time, it’ll get an NSData of the response of that network request.

If some of this idea sounds familiar, it’s because it would act as a nice compliment to Marco Arment’s proposal for recurring network updates:

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.

The two would be welcome on iOS and compliment each other very well. In short, I feel like the multitasking offerings on iOS are still lacking, and the OS often doesn’t reflect what people actually want to do with their devices. By enabling such an API, it would enable people to do more.


One thing I forgot to remember while writing this post was a potential implementation of it could be sort of be done today, but it would be a hack (thanks to Craig Stanford for reminding me about this).

You could do this by enabling “Significant Location Updates” in your application, and then trying to perform the network activity then. With these enabled, iOS will launch your app even if it’s been quit to tell you the device has moved to a new location (typically this is a granularity of a neigbourhood or so). So when the device moves, you get a chance to execute code, and this could include network activity. Instapaper, among others, has a feature to do this, but again, it’s a hack.

Speed of Light