检测手机的震动需要导入
import <AVFoundation/AVFoundation.h>框架
然后实现下面方法即可
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (motion == UIEventSubtypeMotionShake) {
NSLog(@"手机开始摇动");
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//让手机震动
}
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动取消
}