Created
March 23, 2014 19:57
-
-
Save nevyn/9728949 to your computer and use it in GitHub Desktop.
Intercepting shake events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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