How to Play a sound using AVAudioPlayer when in Silent Mode in iPhone

后端 未结 5 2167
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 21:34

I want to play a sound even in silent mode in iPhone.

Can it be done by using AVAudioPlayer (Without using AVAudioSession)

(For ios 3.0+)

Thanks in

5条回答
  •  一个人的身影
    2020-12-02 21:47

    MarkGranoff's solution is correct. However, if you prefer to do it in Obj-c instead of C, the following works as well:

        NSError *error = nil;
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
        [[AVAudioSession sharedInstance] setActive:YES error:&error];
    

提交回复
热议问题