I want to Hook delegate(protocol) method in iOS, who can tell me how to do it?
such as hook method applicationDidFinishLaunching:
I do it like this, but it is not work...
extern IMP original_UIApplication_applicationDidFinishLaunching;
extern void replaced_UIApplication_applicationDidFinishLaunching(UIApplication<UIApplicationDelegate> * self, SEL cmd, UIApplication* application);
MSHookMessageEx(objc_getMetaClass("UIApplication"),
@selector(applicationDidFinishLaunching:),
(IMP)replaced_UIApplication_applicationDidFinishLaunching,
(IMP *)&original_UIApplication_applicationDidFinishLaunching);
applicationDidFinishLaunching is a method implemented by the application DELEGATE, not UIApplication itself. There is absolutely no reason why you would need to swizzle methods on UIApplication. Just implement these methods in your delegate.
For cases where you want to override a method in a class provided by Apple you can do so by creating a category on them. The added category method will override the system method by the same method signature.