I am playing an audio file in the app, so it doesn’t turn off when the phone is locked and the screen is off.
However when I want detect shake it does not work.
It works fine when the app is open and when the screen is locked (not off). The app is definitely running because the logs are working fine.
Any idea?
I use the following code:
-(BOOL)canBecomeFirstResponder {
//make it respond to shake events
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
//make it respond to shake events
[self becomeFirstResponder];
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
NSLog(@"Shake detected");
}
}
This would help you.
This wont let the screen turn off.
Hope this helps.
EDIT:
But Even I feel the same as Akshay does. That it is not possible to capture UIEvent when screen is off.