Created
May 6, 2014 12:31
-
-
Save MP0w/16ff9e1a5fe776632ecc to your computer and use it in GitHub Desktop.
break delegates =)
This file contains 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
// I will not tell you why I made this, or you would think I am mad... | |
// But may be useful in future | |
// | |
// Yes is the equivalent of super.. but it's not allowed in categories | |
+ (void)load{ | |
method_exchangeImplementations(class_getInstanceMethod(self, @selector(setDelegate:)), class_getInstanceMethod(self, @selector(hooked_setDelegate:))); // hook the setDelegate to hook it (later) | |
} | |
- (void)hooked_setDelegate:(id<UIWebViewDelegate>)delegate{ | |
[self hooked_setDelegate:delegate]; // it really call setDelegate: so is not a Loop, is the equivalent of [super setDelegate:delegate] if was allowed in categories... | |
Method hook=class_getInstanceMethod([UIWebView class], @selector(hooked_webViewDidFinishLoad:)); | |
Class delegateClass=[delegate class]; | |
class_addMethod(delegateClass,@selector(hooked_webViewDidFinishLoad:),method_getImplementation(hook),method_getTypeEncoding(hook)); // add the hook method that will be exchanged below with the original one | |
method_exchangeImplementations(class_getInstanceMethod(delegateClass, @selector(webViewDidFinishLoad:)), class_getInstanceMethod(delegateClass, @selector(hooked_webViewDidFinishLoad:))); // finally hooked! | |
} | |
- (void)hooked_webViewDidFinishLoad:(UIWebView *)webview{ | |
[self hooked_webViewDidFinishLoad:webview]; // it really call webViewDidFinishLoad: so is not a Loop, is the equivalent of [super webViewDidFinishLoad:webview] if was allowed in categories... | |
// Do stuff now | |
//..... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment