Sending an SMS

import MessageUI

class inherits from: MFMessageComposeViewControllerDelegate

Implement the following function:
func messageComposeController(_ controller: MFMessageComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
       controller.dismiss(animated: true, completion: nil)
   }

in the method where you need to send the message:
if(MFMessageComposeViewController.canSendText())
        {
            let msgCont = MFMessageComposeViewController()
            msgCont.body = theMessage.text
            msgCont.recipients = [phoneNumber.text!]
            msgCont.messageComposeDelegate = self
            self.present(msgCont, animated: true, completion: nil)
         
        }

Sending to multiple recipients
 let phoneNumberString = "1234567,89101112"
            let recipientsArray = phoneNumberString.components(separatedBy: ",")
            msgCont.recipients = recipientsArray


Comments

Popular posts from this blog

Setting up a playground

Go to another page