//发送邮件:
import MessageUI
func sendEmail(){
guardMFMailComposeViewController.canSendMail()else{
debugPrint("不能发送邮件")
return
}
letemailVC =MFMailComposeViewController()
emailVC.mailComposeDelegate=self// 代理
emailVC.setSubject("邮件标题")
emailVC.setToRecipients(["123@126.com"])
emailVC.setMessageBody("我是邮件正文", isHTML:false)
self.present(emailVC, animated:true, completion:nil)
}
extension xxxxxxx:MFMailComposeViewControllerDelegate{
// MARK: -MFMailComposeViewControllerDelegate
funcmailComposeController(_controller:MFMailComposeViewController, didFinishWith result:MFMailComposeResult, error:Error?){
controller.dismiss(animated:true, completion:nil)
lettoast =ToastView()
switchresult {// 发送状态
case.cancelled:
toast.showToast(text:"取消发送", pos: .Mid)
case.saved:
toast.showToast(text:"保存成功", pos: .Mid)
case.sent:
toast.showToast(text:"发送成功", pos: .Mid)
case.failed:
toast.showToast(text:"发送失败", pos: .Mid)
}
}
}
//发送短信
func sendMessage(){
guardMFMessageComposeViewController.canSendText()else{
debugPrint("不能发送短信")
return
}
letmessageVC = MFMessageComposeViewController()
messageVC.messageComposeDelegate =self// 代理
messageVC.recipients = ["13600000000"]// 收件人
messageVC.body ="短信内容"// 内容
//// 发送主题
//if MFMessageComposeViewController.canSendSubject() {
//messageVC.subject = "阳君"
//}
self.present(messageVC, animated:true, completion:nil)
}
extensionXXXXXXXX:MFMessageComposeViewControllerDelegate{
// MARK: -MFMailComposeViewControllerDelegate
funcmessageComposeViewController(_controller:MFMessageComposeViewController, didFinishWith result:MessageComposeResult){
controller.dismiss(animated:true, completion:nil)
lettoast =ToastView()
switchresult {// 发送状态
case.cancelled:
toast.showToast(text:"取消发送", pos: .Mid)
case.sent:
toast.showToast(text:"发送成功", pos: .Mid)
case.failed:
toast.showToast(text:"发送失败", pos: .Mid)
}
}
}