如何访问私有 API 框架中的方法并将值传递给它?

问题描述

首先 - 我知道私有框架/API 不会让我进入 AppStore,这仅供私人使用/研究。

因此,出于研究目的,我选择了 MFMessageComposer,我想禁用对从代码传递的任何输入的编辑。

我试着把我的手放在这个上面,我用下面的方式编码。我所做的是采用私有框架的路径并访问名为 CKSMSComposeController 的特定类,该类具有上述方法。我引用了 ChatKit.framework https://github.com/nst/iOS-Runtime-Headers/blob/master/PrivateFrameworks/ChatKit.framework/CKSMSComposeController.h

class dump

这是我的代码:

#import "ViewController.h"
#import <MessageUI/MessageUI.h>

@interface ViewController ()<MFMessageComposeViewControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // Here I load the CKSMSController class

    NSBundle *b = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/ChatKit.framework"];
    BOOL success = [b load];
    NSLog(@"Result %@",success ? @"YES" : @"NO");
    Class CKSMSComposeController = NSClassFromString(@"CKSMSComposeController");
     // Passing no to setCanEditRecipients so as to disable the Editing of recepients
     id si = [[CKSMSComposeController alloc] valueForKey:@"init"];
     SEL sel = NSSelectorFromString(@"setCanEditRecipients:");

    if ([CKSMSComposeController respondsToSelector:sel]) {
        BOOL myBool = NO;
        NSNumber *passedValue = [NSNumber numberWithBool:myBool];
    [CKSMSComposeController performSelector:sel withObject:passedValue];
    }
    NSLog(@"ID is%@",si);

}


- (IBAction)sendMessage:(UIButton *)sender {
    if([MFMessageComposeViewController canSendText]) {
        MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init]; // Create message VC
        messageController.messageComposeDelegate = self; // Set delegate to current instance

        NSMutableArray *recipients = [[NSMutableArray alloc] init]; // Create an array to hold the recipients
        [recipients addObject:@"555-555-5555"]; // Append example phone number to array
        messageController.recipients = recipients; // Set the recipients of the message to the created array

        messageController.body = @"Example message"; // Set initial text to example message

        dispatch_async(dispatch_get_main_queue(),^{ // Present VC when possible
            [self presentViewController:messageController animated:YES completion:NULL];
        });
    }
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    [self dismissViewControllerAnimated:YES completion:NULL];
}

@end

我将 NSLog(@"Result %@",success ? @"YES" : @"NO"); 的日志设为 YES,但即使将 NO 传递给上面的选择器,我仍然无法禁用收件人的编辑

有人能告诉我我是否以正确的方式传递参数吗? 因为 -(void)setCanEditRecipients:(BOOL)arg1;` 这是一个私有方法框架接受 bool 作为参数,我在上面的代码中传递 NO

这仅用于私有框架的内部研究。我哪里做错了?。请告诉

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)