AudioServicesPlaySystemSound 播放铃

2024-07-18  本文已影响0人  ios_暗夜行者

AudioServicesPlaySystemSound 播放铃声无效
解决方法:
1.在设置-》声音-〉声音和提醒
设置音量大于0即可
2.静音模式无法播放铃声

+(void)playClickSound
{
    NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"click_sound.mp3" withExtension:nil]; //filename can include extension e.g. @"bang.wav"
    if (fileURL)
    {
        SystemSoundID theSoundID;
        OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)fileURL, &theSoundID);
        if (error == kAudioServicesNoError)
        {
            AudioServicesPlaySystemSoundWithCompletion(theSoundID, ^{
                AudioServicesDisposeSystemSoundID(theSoundID);
            });
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读