You can implement something like this below in a controller (or any UIResponder actually...). These are available in 3.0 and later. You don't have to go down to the level of the accelerometer if you don't want to do advanced stuff, depends on how much detail you want from the shaking.
- (void)viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion==UIEventSubtypeMotionShake) {
if ([self paused]) {
[self play];
}
}
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion==UIEventSubtypeMotionShake) {
if ([self playing]) {
[self pause];
}
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion==UIEventSubtypeMotionShake) {
if ([self playing]) {
[self pause];
}
}
}