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.

Share... Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedInShare on TumblrShare on RedditEmail this to someone

1 Comments
Than Dang
April 28, 2015 at 9:21 am

I can not play system sound like this with iOS8.
Could you have any suggestion?

Leave a Comment

Your email address will not be published. Required fields are marked *

Comment *
Your Name *
Your Email *
Website