zoukankan      html  css  js  c++  java
  • objc/runtime.h 相关

    Objecitve-C的重要特性是Runtime(运行时),在Interacting with the Runtime(交互运行)中,运行时函数部分,苹果给出了/usr/lib/libobjc.A.dylib库,这个共享库提供支持动态属性的objective - c语言,通过其接口,可以用于开发将其他语言运行于Objective-C上的中间层(桥接层),库里的函数定义为纯C语言。

    例如:class_getName

    1. class_getName  
    2. Returns the name of a class.  
    3.   
    4. const char * class_getName(Class cls)  
    5. Parameters  
    6. cls  
    7. class object.  
    8. Return Value  
    9. The name of the class, or the empty string if cls is Nil.  
    10.   
    11. Declared In  
    12. runtime.h  



    这里我们要用库里的函数,干个“坏事”,查看苹果SDK的私有方法。

    第一步:导入头文件

    1. #import <objc/runtime.h>   

    第二步:添加下列代码

     **************实用************

    1. NSString *className = NSStringFromClass([UIView class]);  
    2.   
    3.       
    4.     const char *cClassName = [className UTF8String];  
    5.       
    6.     id theClass = objc_getClass(cClassName);  
    7.       
    8.     unsigned int outCount;  
    9.       
    10.   
    11.     Method *m =  class_copyMethodList(theClass,&outCount);  
    12.       
    13.     NSLog(@"%d",outCount);  
    14.     for (int i = 0; i<outCount; i++) {  
    15.         SEL a = method_getName(*(m+i));  
    16.         NSString *sn = NSStringFromSelector(a);  
    17.         NSLog(@"%@",sn);  
    18.     }   

    第三步:想看什么类 就把UIView换成你想要的

    当然,如果只是查看私有API,会有更简单的方法,可以使用工具class-dump,也可以通过此链接,https://github.com/kennytm/iphone-private-frameworks/tree/master/UIKit/    查看。

    特别注意的是,如果是需要上架的APP,切勿使用私有API,会通不过APP Store的审核。

  • 相关阅读:
    windows下安装pip教程
    python安装扩展”unable to find vcvarsall.bat“的解决办法
    minggw 安装
    Python-- easy_install 的安装
    python 处理中文遇到的编码问题总结 以及 字符str的编码如何判断
    python中的三个读read(),readline()和readlines()
    同时读取两个文件进行while循环
    python 类实例化,修改属性值
    Python if-elif-else
    python 元组
  • 原文地址:https://www.cnblogs.com/tiechui/p/3819805.html
Copyright © 2011-2022 走看看