简体   繁体   中英

Changing the action bound to the send button in MFMessageComposeViewController

I know it's not officially possible. I don't want to release it to the store, it's just a prototype.

I tried finding the button:

MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;

NSArray * allViewControllers = [messageController viewControllers];

for (UIViewController *viewController in allViewControllers)
{
    NSArray *allSubviews = [viewController.view subviews];
    NSLog(@"class name: %@", viewController.class);

    for(UIView *view in allSubviews)
    {
        if([view isMemberOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)view;
            NSLog(@"title: %@", button.titleLabel.text);
        }
    }
}

But nothing worked, so is it possible to change that send button? A sort of a hack? or importing a private header?

Thanks you.

Update:

Tried the following:

NSArray *allSubviews = [[messageController toolbar] subviews];

for(UIView *view in allSubviews)
{
    if ([view isKindOfClass:[UIToolbar class]])
    {
        UIToolbar *navigationBar = (UIToolbar *)view;
        for(UIView *subview in navigationBar.subviews)
        {
            NSLog(@"%@", [subview subviews]);
            if([subview isMemberOfClass:[UIBarButtonItem class]])
            {
                UIBarButtonItem *button = (UIBarButtonItem *)view;
                NSLog(@"title: %@", button.title);
            }
        }

    }

Behind the hood, yes you can trick the label of Send Button.

Officially it is not allowed, but for private use you can use following framework which is available on github. https://github.com/nst/iOS-Runtime-Headers/tree/master/Frameworks/MessageUI.framework .

Instead of default framework include this in your project. And change whatever you want.

If any query let me know i will show the code.

I've never done this but here are some ideas to point you in the right direction.

MFMailComposeViewController is a UINavigationController . The "Send" and "Cancel" buttons are actually in its navigation bar. The navigation bar is a subview of the UINavigationController's view, rather than belonging to any of its children. You are logging the subviews of each child view, so you would never actually see the navigation bar since it is managed by the parent.

Try logging the subviews of the messageController.view , that should give you the navigation bar. The other thing is that you are checking for UIButton whereas you may want to be checking for a UIBarButtonItem .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM