Skip to content

Instantly share code, notes, and snippets.

@nevyn
Created March 23, 2014 19:57
Show Gist options
  • Save nevyn/9728949 to your computer and use it in GitHub Desktop.
Save nevyn/9728949 to your computer and use it in GitHub Desktop.
Intercepting shake events
@implementation UIApplication (GFInterceptEvents)
+ (void)lookback_swizzleSendEvent
{
Method orig = class_getInstanceMethod([UIApplication class], @selector(sendEvent:));
Method repl = class_getInstanceMethod([UIApplication class], @selector(lookback_sendEvent:));
method_exchangeImplementations(orig, repl);
}
- (void)lookback_sendEvent:(UIEvent*)event
{
[self lookback_sendEvent:event];
if(event.type == UIEventTypeTouches) {
[[NSNotificationCenter defaultCenter] postNotificationName:GFInterceptedTouchNotification object:nil userInfo:@{
GFInterceptedEventUserInfoKey: event
}];
} else if(event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake) {
[[NSNotificationCenter defaultCenter] postNotificationName:GFInterceptedShakeNotification object:nil userInfo:@{
GFInterceptedEventUserInfoKey: event
}];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment