I think I've done all I should to detect a shake, but motionEnded:withEvent: never gets called. (One wrinkle is that I don't have a UIViewController - my app is based on the "OpenGL ES App" template.)
I've added application.applicationSupportsShakeToEdit = YES; to my application:didFinishLaunchingWithOptions:, and 
- (BOOL)canBecomeFirstResponder { return YES; }
to EAGLView.m (which does get called), and [self becomeFirstResponder]; to initWithCoder: (and have tried various other places too).
But the debugger never hits
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
Am I missing some step? Do I have to have a controller?
(I'm using iOS 3.2 in the iPad simulator.)
You must add this to your controller:
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}
-(BOOL)becomeFirstResponder
{
    return YES;
}
                        The way the UIResponder chain works with the shake notification is obnoxious.  Seems that UIWindow always gets the notification, and then sub-responders may or may not depending on whats above them in the chain.  I created a UIWindow subclass, and defined it as my window class with the following:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{
    if (event.type == UIEventSubtypeMotionShake) 
        [[NSNotificationCenter defaultCenter] postNotificationName:@"UIEventSubtypeMotionShakeEnded" object:nil];
}
Then, for any views that wanted the shake notifications, I simply had them add themselves as an observer to the UIEventSubtypeMotionShakeEnded event, and they got it every time.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shakeNotification:)
                                             name:@"UIEventSubtypeMotionShakeEnded" object:nil];
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With