I'm using system sound for a kind of notification to my users in an app. Previously, it was working as it should be. I was using
AudioServicesPlaySystemSound(1009);
I get the codes from this site and choose 1009. Later, it stopped working, not playing sounds when it should do. I checked and saw that I should use this:
AudioServicesPlaySystemSoundWithCompletion(theSoundID, ^{
AudioServicesDisposeSystemSoundID(theSoundID);
});
I used this with 1009 and not worked. I reorganised it as:
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);
});
}
}
Still, not working. (I checked whether the file exists or not, it exists. I also check if the phone is in silent mode or not, it is not) However, in the runtime I go to Settings>Sounds and play with Ringer and Alerts volume level. Then I continue (not restart) using app and it plays sounds. After stopping and running again, error starts again. Even while getting sounds, it does not work continuously.
It might be about iOS10, I don't know. What should I do? Thank you!
Ps: I included <AudioToolbox/AudioToolbox.h>