Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Last active March 2, 2023 06:22
Show Gist options
  • Save githubutilities/dfa762a11e1064bfce5f to your computer and use it in GitHub Desktop.
Save githubutilities/dfa762a11e1064bfce5f to your computer and use it in GitHub Desktop.
iOS private framework

iOS private framework

Private framework is for apple use only, and usage of private framework may cause rejection of app submission. You can use class-dump to get method signatures but you can not get any constants or C functions.



How to use it

Calling class method

    //============Calling class method============//
    Class MFMailComposeViewController = (NSClassFromString(@"MFMailComposeViewController"));
    
    if ([MFMailComposeViewController canSendMail] == YES) {
        NSLog(@"can send mail");
    }

Calling instance method

    // please read UIAutocorrectInlinePrompt.h at https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UIAutocorrectInlinePrompt.h
    //============Calling instance method============//
    //============UIAutocorrectInlinePrompt============//
    Class UIAutocorrectInlinePrompt = NSClassFromString(@"UIAutocorrectInlinePrompt");
    id obj = [[UIAutocorrectInlinePrompt alloc] init];
    
    /**
     * using NSObject's performSelector:withObject method
     */
    if ([obj respondsToSelector:@selector(setFrame:)]) {
        // wrap CGRect with object, performSelector:withObject: require object
        NSValue *value = [NSValue valueWithCGRect:CGRectMake(0, 0, 100, 100)];
        [obj performSelector:@selector(setFrame:) withObject:value];
    }
    
    /**
     * using NSInvocation to support limitless argument
     */
    SEL setFrameSelector = @selector(setFrame:);
    if ([obj respondsToSelector:setFrameSelector]) {
        CGRect rect = CGRectMake(0, 0, 200, 200);
        
        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[obj methodSignatureForSelector:setFrameSelector]];
        [inv setSelector:setFrameSelector];
        [inv setTarget:obj];
        [inv setArgument:&rect atIndex:2];  //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
        [inv invoke];
    }
@0209Neha
Copy link

how to do this in swift, xcode version 9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment