How to create email in Swift using Mfmailcomposercontroller correctly?

Asked

Viewed 57 times

0

I’m having trouble creating an email with MFMailComposerController on Swift. When trying to assign self to emailController.mailComposerController I get an error stating that I cannot assign TelaFinalViewController (self) for a value of type MFMailComposerViewController.

I wrote the following code below:

// Teste para possibilidade de envio
        if MFMailComposeViewController.canSendMail(){

            // Criação do Email
            let emailController:MFMailComposeViewController = MFMailComposeViewController()

            emailController.mailComposeDelegate = self // Ocorre o erro aqui!
            emailController.setSubject(assunto)
            emailController.setToRecipients([para])
            emailController.setMessageBody(corpoEmail, isHTML: false)

// Demais implementação ...

        }

Error message:

Cannot assign a value of type "Telafinalviewcontroller" to a value of type 'Mfmailcomposeviewcontrollerdelegate!'

I searched in tutorials and right here in Stackoverflow, but did not find this specifically a solution or explanation for this problem.

It would be a case of bug?

1 answer

1


Make sure your class TelaFinalViewController implements the protocol MFMailComposeViewControllerDelegate.

Example how your class definition should look:

 class TelaFinalViewController: UIViewController, MFMailComposeViewControllerDelegate
  • 1

    Perfect, I just changed the syntax. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.