iPhone App SDK Tutorial: How add vibration in one line of code

iPhone App SDK Tutorial: How add vibration in one line of code

How do you add vibration to your iPhone App code I hear you ask? Well luckily for you, whilst developing my iPhone App (Volt) I had to work this out. I wanted to make the iPhone vibrate everytime the user touched the screen – so when a lightning bolt came out from their finger it felt like they were getting a shock! This feature was a brilliant idea by one of my friends at our local ‘watering hole’…. anyway! Here is how it is done:

Add the folowing framework to your project:
AudioToolbox.framework

Import the following header file:
#import <AudioToolbox/AudioServices.h>

Now use this line of code everytime you want to make the phone vibrate:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Download Volt to see this in action!

Technorati Tags: , , , , , , , , ,