iOS Audio Background Service Works in Simulator, not on Device

EddieLudemaEddieLudema USMember ✭✭

Hi!

Newbie here. Xamarin seems like a pretty cool place to be :smiley: !

I've searched the net (StackOverflow, etc.) and am still having problems with my app. I'm writing a simple real-time audio generation app that needs to run in the background, including when the screen turns off. I've plugged in the following code that I've seen multiple places:

var session = AVAudioSession.SharedInstance();
session.SetCategory(AVAudioSessionCategory.Playback, AVAudioSessionCategoryOptions.MixWithOthers);
session.SetActive(true);
UIApplication.SharedApplication.BeginReceivingRemoteControlEvents(); // For good measure... not sure this is really needed...

This code happens within an InitSystem() function which is called in the end by the FinishedLaunching() function in AppDelegate.cs.

I've also included in my Info.plist file:

Required background modes: App plays audio or streams audio/video using AirPlay

Doing these two things makes the background playback work like a charm on my simulator, but when I deploy to a hard device (iPhone 5), the audio continues if I leave the app for the home screen, but instantly turns off if I press the "power button" to go into sleep mode. Both work great in the simulator, but sleep mode doesn't on the physical device.

Hints, clues? I'm using Visual Studio Community Edition on a Mac, deploying to an iPhone 5.

Thanks!

Eddie

Best Answer

Answers

  • EddieLudemaEddieLudema USMember ✭✭

    Due to time constraints, and some user feedback, I opted out of background audio... On my next project, I'll come back here as a resource! Thanks :)

Sign In or Register to comment.