Created
April 23, 2017 23:32
-
-
Save leodabus/587a5146c1544020fae00260126749ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import MessageUI | |
class MailComposeViewController: MFMailComposeViewController, MFMailComposeViewControllerDelegate { | |
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { | |
controller.dismiss(animated: true) { | |
switch result { | |
case .cancelled: | |
print ("Canceled") | |
case .saved: | |
print ("Saved") | |
case .sent: | |
print ("Sent") | |
case .failed: | |
print ("Error:", error ?? "nil") | |
} | |
} | |
} | |
convenience init?(to: [String], subject: String, body: String) { | |
guard MFMailComposeViewController.canSendMail() else { return nil } | |
self.init() | |
mailComposeDelegate = self | |
setToRecipients(to) | |
setSubject(subject) | |
setMessageBody(body, isHTML: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to call it from your IBAction
@IBAction func ok(_ sender: UIButton) {
}