MethodSwizzle

作者: Superman168 | 来源:发表于2018-07-24 14:50 被阅读0次

    新建工程,注入 Framework后,注入简单测试代码,利用 Runtime 特性交换方法

    #import <objc/message.h>
    
    + (void)load
    {
       // 传入 -id- 类型
    //    object_getClass(id  _Nullable obj)
       // 传入-字符串- 类型
    //    objc_getClass(const char * _Nonnull name)
    
    //    WCAccountLoginControlLogic
    //    onFirstViewRegester
       
       // 获取WC的方法
       Method old_Method = class_getInstanceMethod(objc_getClass("WCAccountLoginControlLogic"), @selector(onFirstViewRegester));
       Method new_Mehod = class_getInstanceMethod(self, @selector(test1));
       
       method_exchangeImplementations(old_Method, new_Mehod);
       
       NSLog(@"加载完成--🍺🍺🍺🍺🍺🍺🍺🍺🍺🍺🍺!!!");
    }
    
    - (void)test1
    {
       NSLog(@"🍺🍺🍺🍺🍺🍺🍺🍺🍺🍺🍺!!!\n 系统检测到异常!!!!!不能注册!!!");
    }
    
    

    相关文章

      网友评论

        本文标题:MethodSwizzle

        本文链接:https://www.haomeiwen.com/subject/uxaemftx.html