0

We can create and show a text composer like so:

let controller = MFMessageComposeViewController()
controller.body = messageText
controller.recipients = numbers
controller.messageComposeDelegate = self
self.present(controller, animated: true, completion: nil)

Is it possible to present an MFMessageComposeViewController with body highlighted so that the user can just start typing to enter a new message if they do not like the default message we have provided?

I looked through the docs but did not find any options for this.

Eric Conner
  • 10,422
  • 6
  • 51
  • 67

1 Answers1

0

No. This is not possible.

The interface for MFMessageComposeViewController does not provide any properties or functions to influence the way it presents the message. Subclassing is no alternative either as the MFMessageComposeViewController doesn't expose any of its view components.

(Just to be 100% correct: You could of course present the MFMessageComposeViewController, then once it's visible traverse its whole view hierarchy until you find a view of class UITextView whose text or attributedText property equals the body text you provided and then set that text view's selectedRange to the full range of the text. While this will probably work (→ untested) I totally discourage you to do that. Encapsulation is there for a reason and if the MFMessageComposeViewController doesn't provide an interface to select text inside its text view it means that you're not supposed to do that.)

Mischa
  • 15,816
  • 8
  • 59
  • 117
  • how can I define a pop-up list with options A and B that the user can choose and then `controller.body` will take the value A or B depending on the selection of the user? – seralouk Mar 28 '20 at 18:45
  • can you please provide the code of how to traverse through the MFMessageComposerViewController? I want to disable the message editing so I need to find that UITextView – user16780334 Jun 29 '21 at 14:05
  • Don't do it. If your app needs to send a message that the user cannot edit (for whatever reason), use a custom view controller for that. Don't make assumptions on how Apple implemented the message view controller and how it reacts. Building hacks based on those assumptions will most certainly break your app at some point and doesn't work reliably. – Mischa Jun 29 '21 at 14:27