System Sounds

To build a system sound, call AudioServicesCreateSystemSoundID with a file URL pointing to the sound file. This call returns an initialized system sound object, which you can then play at will. Just call AudioServicesPlaySystemSound with the sound object. That single call does all the work:

AudioServicesPlaySystemSound(mySound);

When iPod audio is playing, the system sound generally plays back at the same volume, without fading, so users may miss your alert. You can check the current playback state by testing as follows:

if ([MPMusicPlayerController iPodMusicPlayer].playbackState ==      MPMusicPlaybackStatePlaying)

If the music player is playing, you may choose to pause ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.