I am trying to implement MFMailComposeViewControllerwhen sending emails from my application. The problem is that after the presentation, MFMailComposeViewControllerit is not rejected by the Cancel or Send buttons, it only scrolls a bit.
Here is his view:
func mailButtonDidPressed {
let emailTitle = "Test email"
let messageBody = "some body bla bla bla"
let toRecipents = "email@gmail.com"
let emailComposer = MFMailComposeViewController()
emailComposer.setSubject(emailTitle)
emailComposer.setMessageBody(messageBody, isHTML: false)
emailComposer.setToRecipients([toRecipents])
emailComposer.mailComposeDelegate = self
self.presentViewController(emailComposer, animated: true, completion: nil)
}
and rejecting the delegate code:
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
switch (result) {
case MFMailComposeResultSent:
print("You sent the email.")
break
case MFMailComposeResultSaved:
print("You saved a draft of this email")
break
case MFMailComposeResultCancelled:
print("You cancelled sending this email.")
break
case MFMailComposeResultFailed:
print("Mail failed: An error occurred when trying to compose this email")
break
default:
print("An error occurred when trying to compose this email")
break
}
controller.dismissViewControllerAnimated(true, completion: nil)
}
I looked through StackOverflow and other services like this and couldn't find an answer.
source
share