Making the iPhone vibrate (iPhone 振动)

from: http://stackoverflow.com/a/4725039 

There are two seemingly similar functions that take a parameter kSystemSoundID_Vibrate:

1)AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
2)AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

 

Both the functions vibrate the iPhone. But when you use the first function on devices that don’t support vibration, it plays a beep sound. The second function on the other hand does nothing on unsupported devices. So if you are going to vibrate the device continuously, as a alert, common sense says, use function 2.

See also "iPhone Tutorial: Better way to check capabilities of iOS devices" article.

First, add the AudioToolbox framework (AudioToolbox.framework) to your target in Build Phases.

Then, header file to import:

#import <AudioToolbox/AudioServices.h>

 

posted @ 2013-08-26 13:31  有妄想症的猫zz  阅读(262)  评论(0编辑  收藏  举报