Take a look at the motionEnded method: the UIResponder method. You can implement motionEnded in your window, view, or view controller to detect vibrations, for example:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake)
{
}
}
In my application, I needed a shake handler for the entire application. Therefore, I have subclassed UIWindow (my application has one window, like most), and put the handler in this subclass.
source
share