An important feature of objecitve-C is runtime. in interacting with the runtime (Interactive Operation), Apple provides/usr/lib/libobjc. a. dylib library, which provides objective support for dynamic attributes
-C language: the interface can be used to develop the intermediate layer (bridge layer) that runs on objective-C in other languages. The functions in the library are defined as pure C language.
Example: class_getname
class_getNameReturns the name of a class.const char * class_getName(Class cls)ParametersclsA class object.Return ValueThe name of the class, or the empty string if cls is Nil.Declared Inruntime.h
Here we will use the functions in the library to do a "bad thing" and view the private method of the apple SDK.
Step 1: import the header file
#import <objc/runtime.h>
Step 2: Add the following code
NSString *className = NSStringFromClass([UIView class]); const char *cClassName = [className UTF8String]; id theClass = objc_getClass(cClassName); unsigned int outCount; Method *m = class_copyMethodList(theClass,&outCount); NSLog(@"%d",outCount); for (int i = 0; i<outCount; i++) { SEL a = method_getName(*(m+i)); NSString *sn = NSStringFromSelector(a); NSLog(@"%@",sn); }
Step 3: Change uiview to the class you want
Of course, if you just view private APIs, there will be a simpler way to use the tool class-dump, or through this link, https://github.com/kennytm/iphone-private-frameworks/tree/master/UIKit/
View.
Note that if the app needs to be shelved, do not use private APIs, and the app store will not pass the review.
The iOS development group provides technical exchanges and resources. The group number is 241048287.