0

First - I know private frameworks/APIs won't get me to the AppStore, this is for private use/research only.

So as for the research purpose I chose MFMessageComposer I want to disable the editing of any inputs both of which are being passed from the code.

I tried to put my hands on this and I coded in the following manner . What I did is I took the path of the private framework and accessed a particular class called as CKSMSComposeController which have the above mentioned methods . I referred the class dump classes of the ChatKit.framework https://github.com/nst/iOS-Runtime-Headers/blob/master/PrivateFrameworks/ChatKit.framework/CKSMSComposeController.h

I am getting the logs of NSLog(@"Result %@", success ? @"YES" : @"NO"); as YES but still I am unable to disable the edit of recepients even after passing NO to the selector above

Can someone tell am I passing the parameter in a correct way ? Because -(void)setCanEditRecipients:(BOOL)arg1;` which is a method in the private framework accepts bool as parameter and I am passing NO in above code

This is just for internal research on private frameworks. Where I am doing wrong ?.Please tell

User1075
  • 819
  • 15
  • 36
  • If you use KVC for the init method, why don't you use it for the setters? Is `setCanEditRecipients` a class method? – Willeke Jul 01 '21 at 13:37
  • @Willeke '- (void)setCanEditRecipients:(bool)arg1;' it is written like this in the link https://github.com/nst/iOS-Runtime-Headers/blob/master/PrivateFrameworks/ChatKit.framework/CKSMSComposeController.h so perhaps a class method. What you suggest in this case? – User1075 Jul 01 '21 at 14:25

1 Answers1

3

Class methods start with + and instance methods start with - in Objective-C.

// Following is an instance method because it starts with `-`
- (void)setCanEditRecipients:(bool)arg1;

Above method will NOT work with following code.

Class CKSMSComposeController = NSClassFromString(@"CKSMSComposeController");
SEL sel = NSSelectorFromString(@"setCanEditRecipients:");

// `CKSMSComposeController` is a class - NOT an instance
if ([CKSMSComposeController respondsToSelector:sel]) {
    // will not enter if's body
}

On top of all this - you shouldn't create an instance of your own and do customizations on that. You should do the customizations on the instance that's presented by the system on screen.

Here's how you can try that -

- (void) showMessageComposeViewController {
    if ([MFMessageComposeViewController canSendText]) {
        MFMessageComposeViewController* messageController = [[MFMessageComposeViewController alloc] init];
        messageController.recipients = @[@"555-555-5555"];
        messageController.body = @"Example message";
        
        [self presentViewController:messageController animated:YES completion:^{
            
            // Allow enough time for the UI to be loaded fully
            dispatch_after(1, dispatch_get_main_queue(), ^{
                // Since `MFMessageComposeViewController` is a `UINavigationController`, we can access it's first view controller like this
                UIViewController* targetVC = messageController.viewControllers.firstObject;
                
                // Check if the instance is of correct class type
                if ([targetVC isKindOfClass:NSClassFromString(@"CKSMSComposeController")]) {
                    
                    SEL sel1 = NSSelectorFromString(@"setCanEditRecipients:");
                    if ([targetVC respondsToSelector:sel1]) {
                        // put breakpoint here to check whether this line is executed
                        [targetVC performSelector:sel1 withObject:@NO];
                    }
                    
                    SEL sel2 = NSSelectorFromString(@"setTextEntryContentsVisible:");
                    if ([targetVC respondsToSelector:sel2]) {
                        // put breakpoint here to check whether this line is executed
                        [targetVC performSelector:sel2 withObject:@NO];
                    }
                }
            });
        }];
    }
}
Tarun Tyagi
  • 9,364
  • 2
  • 17
  • 30
  • Thanks for the reply but unfortunately the code is not working and it shows the same behaviour , I can edit the recipient as well as edit box. Did you try from your side? – User1075 Jul 01 '21 at 15:18
  • I did the nslog and I can see that the log is printing at the place where you suggested to put breakpoint but unfortunately the code for disabling the edit field and recipient is not working for me. Can you please try from your side? – User1075 Jul 01 '21 at 15:32
  • 1
    @Fionashoff This answer provides information on how to make sure you are calling a private method on an instance. It doesn't guarantee that it'll solve what you were thinking it'll probably solve. Please consider asking a different question. – Tarun Tyagi Jul 01 '21 at 17:55
  • I clearly mentioned in the question that I want to disable the message edit box and add recipient . It is not my mistake that you misunderstood the question. What is the use of the answer if it doesn't works? – User1075 Jul 01 '21 at 17:57