Question

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 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.

Was it helpful?

Solution 2

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

OTHER TIPS

Have you looked at Shaking-Motion Events?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top