16.3. Adding Background Fetch Capabilities to Your Apps

Problem

You want your app to be able to fetch content in the background by using the new capabilities introduced in iOS SDK.

Solution

Add the Background Fetch capability to your app.

Discussion

A lot of the apps that get submitted on a daily basis to the App Store have connectivity to some servers. Some fetch data, some post data, etc. For a while, in iOS, the only way for apps to fetch content in the background was to borrow some time from iOS, as you can read about in Recipe 16.2, and the apps could use that time to complete their work in the background. But this is a very active way of going about doing this. There is a passive way as well, where your app sits there and then iOS gives your app some time to do some processing in the background. So all you have to do is hook into this capability and let iOS wake your app at a quiet moment and ask it to do some processing. This is usually used for background fetches.

For instance, you may need to download some new content. Imagine the Twitter app. All you are interested in when you open that app is to see new tweets. Up until now, the only way to do this was for you to open the app and then let the app refresh the list of tweets. But now iOS is able to wake the Twitter app in the background and ask it to refresh its feed so that when you open the app, all the tweets on the screen are already up to date.

The first thing that we have to do to enable background-fetching capabilities ...

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.