MFMailComposeViewController view does not dismiss 2nd time

前端 未结 1 536
不思量自难忘°
不思量自难忘° 2021-01-06 06:42

I have what I believe is a unique problem. I am having trouble getting my email window to dismiss. I am using Xcode 8.

The email dismisses correctly the first time I

相关标签:
1条回答
  • 2021-01-06 07:01

    You need to create a new MFMailComposeViewController each time. Moving your mail declaration inside sendEmail works…

    func sendEmail(body: String, subject: String) {
        if MFMailComposeViewController.canSendMail() {
    
           // Create a new MFMailComposeViewController…
           let mail = MFMailComposeViewController()
    
            mail.mailComposeDelegate = self
    
            mail.setSubject(subject)
            mail.setMessageBody("\(body)", isHTML: false)
    
            if let data = (body as NSString).data(using: String.Encoding.utf8.rawValue){
                //Attach File
                mail.addAttachmentData(data, mimeType: "text/plain", fileName: "data.txt")
            }
    
            present(mail, animated: true)
        } else {
            // show failure alert
        }
    }
    

    As to why…?

    0 讨论(0)
提交回复
热议问题