How to create emails in Swift using MFMailComposerController correctly?

0

I'm having trouble creating an email with MFMailComposerController in Swift. When I try to assign self to emailController.mailComposerController I get an error stating that I can not assign TelaFinalViewController (self) to 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:

  

Can not assign a value of type "ScreenFinalViewController" to a value of   type 'MFMailComposeViewControllerDelegate!' '

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

Would it be a bug case?

    
asked by anonymous 15.05.2015 / 08:00

1 answer

1

Make sure your TelaFinalViewController class implements the MFMailComposeViewControllerDelegate protocol.

Example how your class definition should look like:

 class TelaFinalViewController: UIViewController, MFMailComposeViewControllerDelegate
    
15.05.2015 / 09:48