I have an app that uses CoreBluetooth
background modes. When a certain event happens I need to play an alarm sound. Everything works fine in the foreground and
By default, AVAudioPlayer
uses the AVAudioSessionCategorySoloAmbient
category, which is silenced by the ringer switch. The AVAudioSessionCategoryPlayback
category is more appropriate for your situation, since it is not silenced by the switch, and will continue to play in the background:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:soundName
ofType:@"caf"]];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[player setCategory:AVAudioSessionCategoryPlayback error:nil];
player.numberOfLoops = -1;
[player setVolume:1.0];