How to detect shake motion in iPhone

On the shake of the iPhone device i want some function to be called, i dont know how to recognize shake so i tried some link and tried this code

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if(event.type == UIEventSubtypeMotionShake)
    {
        NSLog(@"called");
        [self.view setBackgroundColor:[UIColor greenColor]];
    }
}

- (BOOL)canBecomeFirstResponder
{ 
return YES; 
}

But alas no luck so can you please let me know how i can do the same

Thanks and Regards

14
задан Radix 18 May 2011 в 09:19
поделиться