使用MFMessageComposeViewController快速打开带有文本和URL的短信应用

时间:2019-03-01 06:45:48

标签: swift text sms openurl

嗨,我想使用网址打开带有teat的短信应用程序,我编写了以下代码,但是我面对了

类似错误:静态成员'canSendText'不能用于类型为'MFMessageComposeViewController'的实例

List<String> serviceLevel;
List<String> item;
//with gettter and setters.

2 个答案:

答案 0 :(得分:0)

doc中所述,您应该使用:

if MFMessageComposeViewController.canSendText() {
    print("SMS services are available")
}

答案 1 :(得分:0)

尝试一下

//MARK:- Send Mail
//MARK:-

func sendMail(emailTitle : String , messageBody : String , toRecipents : [String]){

    if (MFMailComposeViewController.canSendMail()) {

        let mc: MFMailComposeViewController = MFMailComposeViewController()
        let emailTitle = emailTitle //Feedback
        let messageBody = messageBody //"Feature request or bug report?"
        let toRecipents = toRecipents //["friend@stackoverflow.com"]
        mc.mailComposeDelegate = self
        mc.setSubject(emailTitle)
        mc.setMessageBody(messageBody, isHTML: false)
        mc.setToRecipients(toRecipents)
        self.present(mc, animated: true, completion: nil)

    }else{
        //Show alert
    }
}

呼叫sendMail功能

let urlToShare = "http://www.appzoy.com"
        self.sendMail(emailTitle: "Title of Mail", messageBody: "Hey I just gave an Awesome Assessment on UAssess App you can also try it. I scored , Try to beat my score \(urlToShare)", toRecipents: ["abc@mail.com", "def@mail.com"])