我正在尝试开发一个应用程序,从变量中取一个数字,然后打开"消息"字段To中的(1500)app:以及Text Messages字段like this中的变量值 我尝试了这个答案how to open an URL in Swift3和Swift: How to open a new app when uibutton is tapped,但我没有弄清楚消息应用的网址
我该怎么用?非常感谢。
答案 0 :(得分:0)
使用此
if MFMessageComposeViewController.canSendText() == true{
let recipients:[String] = ["1500"]
var messageController = MFMessageComposeViewController()
//messageController.messageComposeDelegate = self // implement delegate if you want
messageController.recipients = recipients
messageController.body = "Your_text"
self.present(messageController, animated: true, completion: nil)
}
答案 1 :(得分:0)
您需要将“MessageUI”导入您的班级并使用以下代码。
func sendMessages() {
if MFMessageComposeViewController.canSendText() == true {
let recipients:[String] = ["9895249619"]
let messageController = MFMessageComposeViewController()
messageController.messageComposeDelegate = self
messageController.recipients = recipients
messageController.body = "Your_message_text"
self.present(messageController, animated: true, completion: nil)
} else {
//handle text messaging not available
}
}
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
controller.dismiss(animated: true, completion: nil)
}