Playing a system sound in iOS app
We are going to play a system sound from our iOS app. You don’t always need to add to your iPhone or iPad application a audio track to play a sound, because the system has sounds that we can use in our application.
In this case, we are going to play the typical sound “beep“. To do this we will use the AudioToolbox framework.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#import <AudioToolbox/AudioToolbox.h> SystemSoundID mBeep; // Create the sound NSString* path = [[NSBundle mainBundle] pathForResource:@"Beep" ofType:@"aiff"]; NSURL* url = [NSURL fileURLWithPath:path]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep); // Play the sound AudioServicesPlaySystemSound(mBeep); // Dispose of the sound AudioServicesDisposeSystemSoundID(mBeep);
In the official documentation you can read more about this topic, and you can also add vibration to these alerts.