0

我正在使用系统声音在应用程序中向我的用户发出一种通知。以前,它按应有的方式工作。我正在使用

    AudioServicesPlaySystemSound(1009);

我从这个站点获取代码并选择 1009。后来,它停止工作,不应该播放声音。我检查并看到我应该使用这个:

    AudioServicesPlaySystemSoundWithCompletion(theSoundID, ^{
        AudioServicesDisposeSystemSoundID(theSoundID);
    });

我将它与 1009 一起使用,但没有工作。我将其重组为:

    NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/sms-received3.caf"]; //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);
            });
        }
    }

还是行不通。(我检查了文件是否存在,它存在。我还检查了手机是否处于静音模式,它不是) 但是,在运行时我转到设置>声音并播放铃声和警报音量。然后我继续(不重新启动)使用应用程序并播放声音。停止并再次运行后,错误再次开始。即使在收到声音时,它也不会连续工作。

可能是关于iOS10,我不知道。我应该怎么办?谢谢!

ps:我包括<AudioToolbox/AudioToolbox.h>

4

1 回答 1

0

请尝试通过设置AVAudioSession的类别

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory: AVAudioSessionCategoryPlayback  error:&err];
AudioServicesPlaySystemSound(1009);
于 2017-06-15T06:22:07.587 回答