I've implemented a standard way for the user to provide feedback. Is there a way to search through the mail's message (or subject) when the user taps on send or cancel in the mail view controller. The app should perform an action if the mail contains a certain string. The mail need not be sent in that case. Thank you
extension AboutViewController: MFMailComposeViewControllerDelegate {
// MARK: E-Mail
func configureMailComposerViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["support@myapp.app"])
let prefix = NSLocalizedString("Feedback", comment: "")
let title = "\(prefix) - myApp v. \(dataModel.appVersion) / iOS \(UIDevice.current.systemVersion) / \(UIDevice.current.deviceModel())"
mailComposerVC.setSubject(title)
let localisedGreeting = NSLocalizedString("Hi", comment: "")
let localisedMessage = NSLocalizedString("I would like to share the following feedback: ", comment: "")
mailComposerVC.setMessageBody("""
\(localisedGreeting),
\(localisedMessage)
""",
isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertController(title: NSLocalizedString("Mail could not be sent", comment: ""),
message: NSLocalizedString("Please check the email configuration in the device settings and try again.", comment: ""),
preferredStyle: .alert)
sendMailErrorAlert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
present(sendMailErrorAlert, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
// Can I get to the message here? I can't find the property of the controller.
dismiss(animated: true, completion: nil)
}