0

I'm creating an application that allows the user to send a simple email via MFMailComposer. I've already configured that part but i'm trying to figure out, once the email is sent, how do i update the table view showing something like "Email sent" with possibly a time stamp? so far i have a string array that should store the data for emails sent:

var emailSent = [String]()

Any suggestion or help would truly be appreciated!

Geniouse
  • 189
  • 1
  • 4
  • 15
  • What part exactly do you need help with? Do you have code in the mail composer delegate method to check the result? – rmaddy Oct 18 '16 at 17:18

2 Answers2

0

You could create a property in your tableview controller called selectedCellIndexPathRow which you would set in your didSelectRowAtIndexPath method:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    selectedCellIndexPathRow = indexPath.row
    //Open your MailComposeViewController
}

Then, you could do the following once the email is sent:

func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    if result.rawValue == MFMailComposeResult.Sent.rawValue {
        emailSent[selectedCellIndexPathRow] = true
        tableView.reloadData()
    }

    // Dismiss the mail compose view controller.
    controller.dismissViewControllerAnimated(true, completion: nil)
}
Adam Zarn
  • 1,868
  • 1
  • 16
  • 42
0

You could create a custom subclass of MFMailComposerViewController, override setMessageBody and store the sent body for late usage:

class MyMailComposer: MFMailComposeViewController {
    var lastSentBody:String?

    override func setMessageBody(_ body: String, isHTML: Bool) {
        lastSentBody = body
        super.setMessageBody(body, isHTML: isHTML)
    }
}
shallowThought
  • 19,212
  • 9
  • 65
  • 112