Email Form Swift 3

1

I am trying to create a view to send messages to recipients that will be in a database in CoreData, I would like it if someone knows how to implement a view as well as Gmail.

That in the para could be displayed the list of contacts, do searches and show selected.

Someone can guide me how to implement it

    
asked by Mauri figueroa Olivares 20.07.2017 в 18:36
source

1 answer

1

The MFMailComposeViewController class gives you the view you want. The disadvantage for what you want is that you can access from that view to some emails available in CoreData, since from this view you only access the emails in your calendar. A possible solution would be that you first create a view in which you access that list of emails and you can select them, and then present MFMailComposeViewController with the emails already chosen.

import MessageUI

class vistaCorreos: UIViewController, MFMailComposeViewControllerDelegate {

var arrayCorreos : [String] = []
override func viewDidLoad() {
    super.viewDidLoad()
}

@IBAction func sendEmail(_ sender: UIButton) {      
    let mailComposerVC = MFMailComposeViewController()
    mailComposerVC.mailComposeDelegate = self
    mailComposerVC.setToRecipients(arrayCorreos)
    mailComposerVC.setSubject("") //Puedes predeterminar un asunto o dejarlo vacío
    mailComposerVC.setMessageBody("", isHTML: false)
    self.present(mailComposerVC, animated: true, completion: nil)
}

func mailComposeController(controller: MFMailComposeViewController,
                       didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    // Aquí puedes comprobar si se ha enviado o no y cerrar al terminar
    controller.dismiss(animated: true, completion: nil)
}

Here you can find the apple documentation

    
answered by 21.07.2017 в 08:46