Recipe: Simple Audio Alerts

Audio alerts “speak” directly to your users. They produce instant feedback—for users who are not hearing impaired. Fortunately, Apple built basic sound playback into the Cocoa Touch SDK through System Audio services.

The alternatives include using Audio Queue calls or AVAudioPlayer. Audio Queue playback is time-consuming to program and involves much more complexity than simple alert sounds need. In contrast, you can load and play system audio with just a few lines of code. AVAudioPlayer also has drawbacks. It interferes with iPod audio. In contrast, System Audio can perform a sound without interrupting any music that’s currently playing, although that may admittedly not be the result you’re looking for, as alerts ...

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.