Obtain the private API under the SDK for iOS development

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.