How can I programmatically trigger the shake event in iOS?
I've tried the following but it keeps crashing...
+ (void)shake {
NSLog(@"TEST");
UIMotionEventProxy *m = [[NSClassFromString(@"UIMotionEvent") alloc] _init];
m->_subtype = UIEventSubtypeMotionShake;
m->_shakeState = 1;
[[[UIApplication sharedApplication] keyWindow] motionBegan:UIEventSubtypeMotionShake withEvent:m];
[[[UIApplication sharedApplication] keyWindow] motionEnded:UIEventSubtypeMotionShake withEvent:m];
}
What does apple do in the simulator under Hardware > Shake Gesture?
Try to replace
UIMotionEventProxy *m = [[NSClassFromString(@"UIMotionEvent") alloc] _init];
with
UIMotionEventProxy *m = [[UIMotionEventProxy alloc] _init];
I guess it's crushing when NSClassFromString(@"UIMotionEvent") returns 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