Even with all the above options, I recently was in need of a simple way (read, with little code) to have an audible cue to know when my app reached a certain point of execution. The reason being, the section of code I needed to debug was not accessible through a breakpoint, as the code was called as part of a Push Notification and was only invoked if the app was not running.
I began my search hoping to find a simple way to play a beep (as is common on non-smart phone devices or a PC). What I settled on was calling a method to vibrate the phone, which in turn also has an audible effect. The code below is handy whenever you need to vibrate the iPhone, for whatever reason.
Vibrating the iPhone
Here are the steps:
- Add the AudioToolbox framework to your app
- Import the AudioToolbox header file
- Call the method void AudioServicesPlayAlertSound (SystemSoundID inSystemSoundID)
In place of creating your own SystemSoundID from a file or other resource (see Audio Session Services), you can use the constant kSystemSoundID_Vibrate.
#import <AudioToolbox/AudioToolbox.h> ... AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
And for the iPod touch?
Unfortunately, if you run this code on an iPod touch, it has no effect. Note to self, debug the application on an iPhone before running on an iPod.