Sending SMS using MFMessageComposeViewController
<p>I want my app to send SMS and my current code didn't work, here is the steps  follow:</p>

<pre><code>import MessageUI
</code></pre>

<p>add the class:</p>

<p><code>MFMessageComposeViewControllerDelegate</code></p>

<p>then I used a button:</p>

<pre><code> @IBAction func Messages(_ sender: UIButton) {


    if MFMessageComposeViewController.canSendText() == true{
        let recipients:[String] = ["1500"]
        let messageController = MFMessageComposeViewController()
        messageController.messageComposeDelegate  = self // implement delegate if you want
        messageController.recipients = recipients
        messageController.body = "Your_text"
        self.present(messageController, animated: true, completion: nil)

        func messageComposeViewController(controller: MFMessageComposeViewController,
                                          didFinishWithResult result: MessageComposeResult) {

            // Dismiss the message compose view controller.
            controller.dismiss(animated: true, completion: nil)}

    }}
</code></pre>

<p>and use the function:</p>

<pre><code> func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {}
</code></pre>

<p>so what did I missed? thank you.</p>