Couldn't detect device's shakes
I'm trying to detect when the device(iPhone/iPod Touch) shakes, what I have already done (in my viewController.m) is :
- (BOOL) canBecomeFirstResponder{
return YES;
}
.
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (motion == UIEventSubtypeMotionShake){
NSLog(@"Motion detected");
}
}
and 开发者_JS百科I've added this line to viewDidLoad :
BOOL ret = [self becomeFirstResponder];
Then, I build&ran the app, and tried to shake the device but nothing happened!.. I started troubleshooting the problem, by using Breakpoints, what I detected is that the "ret" value returned from [self becomeFirstResponder] is "NO". And couldn't know what is the problem. Any help ?
Info : using Xcode 4, and iOS 4.3
Thanks in advance.
Have you looked at Shaking-Motion Events?
I actually found the solution..
[self becomeFirstResponder];
should be only implemented in viewDidAppear: because I tried it in viewWillAppear: and viewDidLoad and it's not working in the both methods.
Thanks
精彩评论