# iOS background audio works on emulator, not on device

**URL:** <https://forum.ionicframework.com/t/ios-background-audio-works-on-emulator-not-on-device/12948>\
**Category:** ionic-v1\
**Created:** [November 20, 2014, 2:28am UTC](https://forum.ionicframework.com/t/ios-background-audio-works-on-emulator-not-on-device/12948 "2014-11-20T02:28:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_spriggs](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@martin\_spriggs](https://forum.ionicframework.com/u/martin_spriggs)\
**Post date:** [November 20, 2014, 2:28am UTC](https://forum.ionicframework.com/t/ios-background-audio-works-on-emulator-not-on-device/12948/1 "2014-11-20T02:28:07Z")

</div>

Curious question… I’m using ng-cordova media and want to allow background audio on the iOS build. When I run it in Xcode or the emulator, background audio does work when I either lock the emulator or hit the home button. This is the behavior I would expect. However, when I load the app on an actually iPhone, audio stops on lock or home. What am I missing? Is this a bug in CLI? Not updating a plist setting or something? Thanks.

---

<div class="post-metadata">

**Author:** ![dhanai](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@dhanai](https://forum.ionicframework.com/u/dhanai)\
**Post date:** [November 20, 2014, 9:14am UTC](https://forum.ionicframework.com/t/ios-background-audio-works-on-emulator-not-on-device/12948/2 "2014-11-20T09:14:05Z")

</div>

This worked for me:

**If you need background audio, you will need to add the supported modes in your -info.plist**

```
<key>UIBackgroundModes</key>
    <array>
        <string>audio</string>
    </array>

```

Also important to note, since iOS6, you must explicitly set the AVAudioSessionCategory.

> <https://stackoverflow.com/questions/11616001/uiwebview-html5-audio-pauses-in-ios-6-when-app-enters-background/12414719#12414719>

**First, import AVFoundation into your AppDelegate.m**

`#import <AVFoundation/AVFoundation.h>`

_Then add the following to application:(UIApplication)application didFinishLaunchingWithOptions:(NSDictionary_)launchOptions\*\*

```
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];

```

Taken from: [https://github.com/devgeeks/ExampleHTML5AudioStreaming](https://github.com/devgeeks/ExampleHTML5AudioStreaming)
