嗨我想用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)
}
}
}
如doc所述,你应该使用:
if MFMessageComposeViewController.canSendText() {
print("SMS services are available")
}
试试这个
//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]"])