使用快速iOS发送短信

时间:2018-08-23 12:04:13

标签: ios swift

它无法正常工作,并抛出以下错误, “应用程序试图在目标上显示一个零模态视图控制器”

预先感谢

@IBAction func sms(_ sender: Any)
{
    var messageVC = MFMessageComposeViewController()
    messageVC.messageComposeDelegate = self

    messageVC.body = "Enter a message";
    messageVC.recipients = ["Enter tel-nr"]

    self.present(messageVC, animated: false, completion: nil)


}

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

1 个答案:

答案 0 :(得分:0)

尝试在具有短信功能的真实设备上,而不是在iOS模拟器上。