【问题标题】:Add recipient in MFMailComposeViewController from Label represented在 MFMailComposeViewController 中从代表的标签添加收件人
【发布时间】:2020-06-22 06:15:08
【问题描述】:

我有一个应用程序允许用户通过 MFMailcomposeViewController 发送电子邮件。

composeVC.setToRecipients(["email@gmail.com"]) 

在同一个视图控制器中,我有一个标签,它代表从 Firestore 下载的人员的电子邮件。我怎么能setToRecipients而不是(["email@gmail.com"])到(["mailRepresentedLabel@gmail.com"]

我希望它从邮件代表标签中提取数据并将其自动添加到收件人,因此最终用户不需要将电子邮件添加到 setToRecipient 它将自动从 mailRepresentedLabel 中提取

请帮忙。

我当前的代码是这样的

               if !MFMailComposeViewController.canSendMail() {
                   print("Не удается отправить Имэйл")
                   return
               }
               let composeVC = MFMailComposeViewController()
               composeVC.mailComposeDelegate = self
                
               // Configure the fields of the interface.
        composeVC.setToRecipients(["\(String(describing: mailRepLabel))"])
               composeVC.setSubject("Register your client details with us")
               composeVC.setMessageBody("Dear agent please register your client with us by replying on that email in order for us to track the information that this client is came with you. if aftersometime the client would like to come without you we will always have the information that this client is came with you and we will send him back to you. Please reply with the following details: Client Name, Passport number Property Managers name.", isHTML: false)
                
               // Present the view controller modally.
               self.present(composeVC, animated: true, completion: nil)
               print("done")
           }
    
}

extension AgentViewController: MFMailComposeViewControllerDelegate {
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        if let _ = error {
            controller.dismiss(animated: true)
        
        return
        
        }
        switch result {
        case .cancelled:
            print("Canceled")
        case.failed:
            print("Failed to send")
        case.saved:
            print("Saved")
        case.sent:
            print("Email Sent")
        }
        controller.dismiss(animated: true)
    }
}```

【问题讨论】:

  • 除了含糊不清的mailRepLabel 代码不包含任何关于标签的信息。

标签: ios swift email mfmailcomposeviewcontroller


【解决方案1】:

您可以使用text 属性访问标签的文本内容。所以...像这样的东西?

mailComposer.setToRecipients([mailRepLabel.text])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多