将method_exchangeImplementations与block_invoke方法一起使用

时间:2020-10-28 01:57:21

标签: objective-c hook

我正在尝试用以下代码替换方法实现

BOOL ct_hookMethod(Class originalClass, SEL originalSelector, Class swizzledClass, SEL swizzledSelector)
{
    Method originalMethod = class_getInstanceMethod(originalClass, originalSelector);
    Method swizzledMethod = class_getInstanceMethod(swizzledClass, swizzledSelector);

    if (originalMethod && swizzledMethod)
    {
        method_exchangeImplementations(originalMethod, swizzledMethod);
        return YES;
    }

    return NO;
}

它适用于-[xxxView runRequest:]之类的选择器,但不适用于-[xxView runRequest:]_block_invoke:之类的方法。

有人知道如何钩住他们吗?

0 个答案:

没有答案