iPhone:如何独立于音量设置播放本地通知声音?

puo*_*uot 8 iphone audio notifications volume local

FoneHome iPhone应用程序有一个功能,您可以播放声音作为本地通知的一部分.无论iPhone的音量设置如何,声音都很响.

如何获得本地通知(或推送)来播放与当前iPhone音量水平无关的大声音频警报?我尝试将soundName设置为WAV文件,但无论当前音量是多少,它都会播放,我看不到任何设置选项.

jam*_*obo 2

尝试使用以下代码

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[audioPlayer setVolume:x];
if (audioPlayer == nil)
    NSLog([error description]);             
else 
    [audioPlayer play];
Run Code Online (Sandbox Code Playgroud)

这里“x”是一个浮点值,通常范围从 0.0 到 1.0。但是,要增加音量级别,请指定 x 值 >10.0。但这样做可能会使声音稍微失真。