0

I want to traverse through the view hierarch of the MFMessageComposerController so that I can get the instance of UITextField where the messages are populated . Here is the code which I did in Swift for presenting MFMessageController . How can I traverse through its hierarchy?

The code :

@IBAction func sendSmsClick(_ sender: AnyObject) {
        guard MFMessageComposeViewController.canSendText() else {
        return
    }

    let messageVC = MFMessageComposeViewController()
    messageVC.view.endEditing(true)
    messageVC.body = "Enter a message";
    messageVC.recipients = ["Enter tel-nr"]
    messageVC.messageComposeDelegate = self;
    NSLog("Subviews %@", messageVC.view.subviews);
   // self.view.endEditing(true)

self.present(messageVC, animated: false) {
   
}
}

func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
    switch (result.rawValue) {
        case MessageComposeResult.cancelled.rawValue:
        print("Message was cancelled")
        self.dismiss(animated: true, completion: nil)
    case MessageComposeResult.failed.rawValue:
        print("Message failed")
        self.dismiss(animated: true, completion: nil)
    case MessageComposeResult.sent.rawValue:
        print("Message was sent")
        self.dismiss(animated: true, completion: nil)
    default:
        break;
    }
}

Can anyone tell how to traverse through the view hierarchy of the MFMessageViewController?

The result of the NSLOG

enter image description here

The agenda of me is to mimic the same as shown in this app. To find the textfield and to Disable the editing . The app from Appstore:

user16780334
  • 422
  • 5
  • 20
  • `NSLog("Subviews %@", messageVC.view.subviews);` did it work at least? Any output? I'd call maybe `loadView` to force loading. Also, Debug View Hierarchy of XCode might help too. BUT, since it's private, I wouldn't recommand doing that. – Larme Jun 29 '21 at 14:19
  • @larme I have updated the question with the output which I got from the NSLog . And yes the main agenda for me is to disable the editing of MFMessageComposer which I found in one of the App Store app.. The gif of that is attached – user16780334 Jun 29 '21 at 14:28
  • Well, you need to iterate again on he subviews... There are plenty of views and subviews I guess... But again, you saw it on an app, but it might be rejected for that reason too. – Larme Jun 29 '21 at 14:34
  • @Larme yes the behaviour is on multiple apps. Can you please help me on how to traverse through the views of MFMessageComposer? – user16780334 Jun 29 '21 at 14:40
  • You did `NSLog("Subviews %@", messageVC.view.subviews);`? Well, you have a `NSArray` of `UIView`, call `subview` on them too, etc. You can use a for loop, a while, loop, etc. – Larme Jun 29 '21 at 14:41
  • @Larme I am totally out of mind ... could you please help me with an answer of how to traverse through the UIView NSArray? – user16780334 Jun 29 '21 at 14:49
  • https://stackoverflow.com/questions/2746478/how-can-i-loop-through-all-subviews-of-a-uiview-and-their-subviews-and-their-su ? That's my first found while searching. Did you try Debug View Hierarchy too? Does it work for that ViewController? – Larme Jun 29 '21 at 14:56
  • @Larme unfortunately MFMessageComposer doesn't works on Simulator and while trying to debug in iPhone device it shows error fetching debug hierarchy – user16780334 Jun 29 '21 at 15:20
  • You could also try [revealapp](https://revealapp.com/) – Paulw11 Jun 30 '21 at 03:21

0 Answers0