Jump to content
Cartman.

iOS SDK Snippet: iPhone Vibration

Recommended Posts

Posted

With this iOS SDK code snippet, you will learn how to cause the iPhone to vibrate with the AudioToolbox framework and a single line of code.

Creating a vibration is simple as pie - simpler in fact. It just requires one line of code; two if you add the import line. But as simple as a one-liner is it is better to make it into a function. So here is the one liner, followed by the function. Cheers


/ NOTE: You need to import the AudioToolbox for access to the vibrate
#import <AudioToolbox/AudioToolbox.h>
*
// The one-liner:
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
*
// The function:
- (void)vibrate {
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
}
*
// The call from within another method in the same class:
- (void)myMethod {
[self vibrate];
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...