AudioServicesPlaySystemSound not playing any sound in iOS 8 device

AppsDev picture AppsDev · Sep 10, 2015 · Viewed 8.4k times · Source

I have AVFoundation and AudioToolbox frameworks added to my project. In the class from where I want to play a system sound, I #include <AudioToolbox/AudioToolbox.h> and I call AudioServicesPlaySystemSound(1007);. I'm testing in a device running iOS 8, sounds are on and volume is high enough, but I don't hear any system sound when I run the app and AudioServicesPlaySystemSound(1007); is called... what could I be missing?

Answer

Tiago Almeida picture Tiago Almeida · Sep 23, 2016

With iOS10 playing audio like this doesn't work:

SystemSoundID audioID;

AudioServicesCreateSystemSoundID((__bridge CFURLRef)pathURL, &mySSID);
AudioServicesPlaySystemSound(audioID);

Use this instead:

AudioServicesCreateSystemSoundID((__bridge CFURLRef)pathURL, &audioID);

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