【问题标题】:Get email and time stamp from sent emails saved on a tableview从保存在表格视图中的已发送电子邮件中获取电子邮件和时间戳
【发布时间】:2016-08-23 20:32:12
【问题描述】:

我正在使用 MFMailComposeViewController 发送电子邮件,但在您发送电子邮件后,我想在表格视图上显示电子邮件和时间。我该怎么做?

我的表代码是基本的

//This is empty, just to populate the empty table for now
var sentEmails = [String]()

//Number of Sections
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

//Number of Rows
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return sentEmails.count
}

//Cell Configuration
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)

    let row = indexPath.row
    cell.textLabel?.text = sentEmails[row] //Email here?
    cell.detailTextLabel?.text = "time stamp"//maybe?

    return cell
}

这是我的邮件代码

 func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) {

    //Checks if composer can sent email
    if MFMailComposeViewController.canSendMail() {

        let mail = MFMailComposeViewController()

        mail.mailComposeDelegate = self

        //Add the email to the recipient field
        if let emailAddress = contactProperty.value as? String {
            mail.setToRecipients([emailAddress])
        }

        //Dismisses the current view and presents the mail composer view
        self.dismissViewControllerAnimated(true, completion: {() -> Void in
            self.presentViewController(mail, animated: true, completion: nil)
        })

    } else {
        print("send error")
    }
}

//Dismiss Buttons for Mail Composer
func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError?) {

    switch result {
    case MFMailComposeResultCancelled:
        print("Mail Cancelled")
    case MFMailComposeResultSaved:
        print("Mail Saved")
    case MFMailComposeResultSent:
        print("Mail Sent")
    case MFMailComposeResultFailed:
        print("Mail sent failure: \(error)")
    default:
        break
    }

    controller.dismissViewControllerAnimated(true, completion: nil)
}

我怎样才能获得发送的电子邮件和时间显示在我的桌子上?先感谢您。

【问题讨论】:

    标签: swift tableview mfmailcomposer


    【解决方案1】:

    MFMailComposeViewController 运行结束,并且设计上除了完成状态之外不提供任何更多信息。

    如果您想了解更多信息,则需要手动实现发送电子邮件,这可能是一项非常繁琐的任务,我强烈建议您不要这样做,除非这是您产品的核心。

    更新您无法使用内置邮件编辑器获取它。如果您更喜欢重新实现电子邮件客户端,有几个开源客户端:http://libmailcore.com; (请记住,您将无法访问迫使她从头开始设置帐户的用户帐户)。或者,您可以实现从您的服务器或仅在客户端提供 UI 的 3rd 方服务发送电子邮件,例如第三方服务https://github.com/sendgrid/sendgrid-objc

    【讨论】:

    • 那么我如何获得我发送的时间和电子邮件?我只需要这些信息,没有别的。我是 swift 新手,所以我不太熟悉它的工作原理。
    • 感谢您的更新。你只是给了我一个想法。在完成区域,我可以发送我刚刚使用的电子邮件和当前的 NSDate,然后将其发送到一个数组。不知道怎么做,但听起来是个好主意。
    猜你喜欢
    • 2017-06-11
    • 2010-09-18
    • 2023-03-27
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多