THY-IPhone
THY-IPhone

Reputation: 31

iOS is it possible to play local notification sound when device is on mute

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

Answers (3)

rockstarberlin
rockstarberlin

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

Richard Clark
Richard Clark

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

MechEthan
MechEthan

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

Related Questions