*For most background modes you need to add a key in info.plist
to indicate that the app wants to run code while in the
background.
1. Click the project on the File Navigator;
2. Click info;
3. Click on the (+) that appears when you hover over any line
of the list;
4. Choose Required Background Modes in the list that appears.
When you select this item, Xcode will create an array below the
item with one blank item. Expand the list on the right and select
App plays audio. In this list, you can see all background modes
this tutorial covers - as well as a few more that you can't use
without specialized hardware.
*Receiving Location Update
You can control the accuracy of these location updates and
even change that accuracy while background.
*It is important that you call endBackgroundTask: for every
time you call beginBackgroundTaskWithExpirationHandler:.
*Processing Newsstand Kit Downloads
Newsstand mode is very specific to Newsstand apps. It provides
a set of APIs that make it easy for your app to start a very large
file download even if your app is not active (using push
notifications) and keeping going until the whole file has been
downloaded.
You can't use this mode without declaring that your app is a
Newsstand app, or the code will not work as
intended.
*VoIP
This mode is better than the "10min background" because you
can run the code for an indefinite amount of time. Better yet,
if the app
crashes or the user reboots the phone, the app is started
automatically in the background.
With the call to setKeepAliveTimeout:handler: you can set a
handler that will be called periodically while the app is in the
background. This allows your app to do anything, but it should be
used to send a "ping" to your server to keep the connection alive.
You've configured it to be called every 10 minutes -- the minimum
value allowed for this method, according to the documentation. All
you're doing here is sending a ping command to the server and
logging the event.
Your handler has a maximum of 10 seconds to perform any needed
tasks and exit. If it does not exit before time expires, the app is
suspended.
Timeout values and handlers are not persisted between app
launches. Therefore, if your app is terminated for any reason, you
must reinstall the handler during the next launch cycle.