steipete / Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.

Home Page:https://twitter.com/steipete

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

this is a resolution to support hook static method

Assuner-Lee opened this issue · comments

  1. get meta-Class from class :
    Class cls = object_getClass(self.class);

  2. hook:
    [cls aspect_hookSelector:selector withOptions:options usingBlock:block error:error];

!!!!!!!

Nice work @Assuner-Lee , I can confirm this works! I used it to swizzle:

[MFMailComposeViewController canSendMail]

Been looking for this for awhile!

@Assuner-Lee @varun531 If had hooked a static method using the above method, then you try to hook a instance method and call the instance method, it would be crashed!

May you can also try Stinger https://github.com/eleme/Stinger

@Assuner-Lee @varun531 If had hooked a static method using the above method, then you try to hook a instance method and call the instance method, it would be crashed!

May you can also try Stinger https://github.com/eleme/Stinger