steipete / Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.
https://twitter.com/steipete
MIT License
8.4k stars 1.26k forks source link

this is a resolution to support hook static method #133

Open Assuner-Lee opened 6 years ago

Assuner-Lee commented 6 years ago
  1. get meta-Class from class :
    Class cls = object_getClass(self.class);

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

!!!!!!!

varun531 commented 6 years ago

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

[MFMailComposeViewController canSendMail]

Been looking for this for awhile!

xxfenxx commented 6 years ago

@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!

Assuner-Lee commented 4 years ago

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

Assuner-Lee commented 4 years ago

@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