Reputation: 31
I'm developing alarm clock which needs to wake up when receiving local notification. but when the device on mute I cannot hear anything, I'm asking because I saw 2 apps which implemented that i.e (radio alarm). thanks, tomer.
Upvotes: 0
Views: 2493
Reputation: 1853
-(void)playSound:(NSString *)filePath
{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:filePath]];
[playerItem addObserver:self forKeyPath:@"status" options:0 context:0];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
self.audioPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[self.audioPlayer play];
}
Upvotes: 0
Reputation: 1
RadioAlarm, I'm almost certain, is able to play when muted because it keeps itself running in the background. For a NORMAL local notification (i.e. one that fires even after the app finishes), I have not found a way to overcome the mute switch or the ringer volume.
Upvotes: 0
Reputation: 5703
Check out AVAudioSession
's setCategory
function -- it should do the trick for you.
Here's a link for info on the categories: developer.apple.com - Audio Session Categories
Upvotes: 3