使用MFMessageComposeViewController在swift中打开带有文本和URL的短信应用程序

问题描述 投票:0回答:2

嗨我想用urt打开短信应用程序我写下面的代码,但我面对

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

var controller1 = MFMessageComposeViewController()
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

            if indexPath.section == 0
            {
                if (controller1.canSendText()) {

                    let urlToShare = "http://www.appzoy.com"

                    controller1.body = "Hey I just gave an Awesome Assessment on UAssess App you can also try it. I scored , Try to beat my score \(urlToShare)"

                    controller1.messageComposeDelegate = self as? MFMessageComposeViewControllerDelegate
                    self.present(controller1, animated: true, completion: nil)
                }
            }
    }
swift text sms openurl
2个回答
0
投票

doc所述,你应该使用:

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

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 //["[email protected]"]
        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: ["[email protected]", "[email protected]"])
© www.soinside.com 2019 - 2024. All rights reserved.