Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

12. Multitasking > 12.4. Playing Audio in the Background

12.4. Playing Audio in the Background

Problem

You are writing an application that plays audio files (such as a music player) and you would like the audio files to be played even if your application is running in the background.

Solution

Create a new array key in your application’s main .plist file. Set the name of the key to UIBackgroundModes. Add the value audio to this new key. Here is an example of the contents of a .plist file with the aforementioned key and value added:

<dict>
  ...
  ...
  ...
  <key>UIBackgroundModes</key>
  <array>
    <string>audio</string>
  </array>
  ...
  ...
  ...
</dict>

Now you can use the AV Foundation to play audio files, and your audio files will be played even if your application is in the background.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial