3

I’ve seen many things that mention using MessageUI Framework for COMPOSING messages, but is there a way to automate SENDING it in Swift? Perhaps even allowing my code to run once the Send Button is pressed, then I call the actual method to send it.

Lou Valencia
  • 188
  • 2
  • 6
  • No. It requires user action. This allow to avoid undesired spam. You need to use a third party code (with server, etc. and it may costs money, because it's SMS, and phone companies charge it). – Larme May 07 '18 at 07:24

1 Answers1

3

You can't just send a message without user's confirmation, but you can present the MFMessageComposeViewController at any time you want.

import MessageUI

func sendSMS(with text: String) {
    if MFMessageComposeViewController.canSendText() {
        let messageComposeViewController = MFMessageComposeViewController()
        messageComposeViewController.body = text
        present(messageComposeViewController, animated: true, completion: nil)
    }
} 
Au Ris
  • 4,541
  • 2
  • 26
  • 53