How to play simple system sound

I just need to play a simple sound, I have an application that sends messages, and I need to play the sound of a “sent message” when sending a message.

+3
source share
2 answers

This is how I play the sound system. As simple as possible. Just find the name of the sound you are trying to play.

Remember to import #import <AVFoundation/AVFoundation.h>
and add AVFoundation.frameworkgoals to the build phases.

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"]] error:NULL];
[audioPlayer play];
+6
source

Take a look at AudioServicesPlayAlertSoundthe iOS Help System Sound System Reference

+3
source