我正在从Firebase数据库中检索电话号码,无论我如何将其输入数据库中,它都会在我的设备上返回错误:
“消息发送到无效的目的地。请检查您的电话号码,然后重试。消息2127”
发送文本后,该消息会以自动回复的形式出现。我尝试将其作为111-111-1111
和1111111111
输入到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)
}
}
}
最佳答案
我不得不改变
messageVC.recipients = [“ tel:(contactopt)”]
messageVC.recipients = [String(contactopt)]