Play local notification default sound when displaying UIAlertView?

前端 未结 4 1391
不知归路
不知归路 2020-12-04 10:19

I\'m writing a reminders app for iPhone that displays reminders using local notifications.

If a reminder goes off while the application is running, the local notific

4条回答
  •  Happy的楠姐
    2020-12-04 10:42

    This is addition to Andrew Little answer.

    To better mimic notification sound, you also should to configure audio session:

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionDuckOthers error:nil];
    

    This is essential when e.g. you listen to the music and obtain notification during this.

    Parameters of session above looks the same as for sound played when notification fires with application in background:

    • music is silenced before and resumed after notification sound.
    • device silence switch is handled correctly - sound is played only when switch is on
    • volume is the same (note you may obtain different volume if you use system sound when application in background and files from Andrew Little answer)

提交回复
热议问题