文本消息功能在设备上返回错误

时间:2017-04-08 23:29:50

标签: ios swift firebase firebase-realtime-database sms

我正在从Firebase数据库中检索电话号码,无论我如何将其输入数据库,它都会在我的设备上返回错误:

  

“邮件已发送到无效目的地。请检查您的号码,然后重试.Msg 2127”

邮件在文本发送后立即自动回复。我尝试将其作为111-111-11111111111111输入firebase(实际上不使用数字1,而是使用真实的电话号码)。

调用函数工作正常但是发短信的号码不起作用。

var contact: Int!
@IBAction func textButton(_ sender: Any) {
    if canSendText() {
          if let contactopt = contact{
            var messageVC = MFMessageComposeViewController()
        messageVC.recipients = ["tel:\(contactopt)"]
        messageVC.messageComposeDelegate = self;

            self.present(messageVC, animated: false, completion: nil)}}
    else {
        let errorAlert = UIAlertView(title: "Cannot Send Text Message", message: "Your device is not able to send text messages.", delegate: self, cancelButtonTitle: "OK")
        errorAlert.show()
    }

}


func canSendText() -> Bool {
    return MFMessageComposeViewController.canSendText()
}

func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {

    controller.dismiss(animated: true, completion: nil)
}


 @IBAction func callButton(_ sender: UIButton) {

    if let contactopt = contact{

    if let url = NSURL(string: "tel://\(contactopt)") {
    //    UIApplication.shared.openURL(url as URL)
        UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)

}
}
}

1 个答案:

答案 0 :(得分:0)

我不得不改变   messageVC.recipients = [" tel:(contactopt)"]

messageVC.recipients = [String(contactopt)]