Skip to content

Instantly share code, notes, and snippets.

@superarts
Created June 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superarts/b10c3997ddb62b97a155 to your computer and use it in GitHub Desktop.
Save superarts/b10c3997ddb62b97a155 to your computer and use it in GitHub Desktop.
Simple Mail Composer in Swift
@IBAction func action_report() {
let composer = SVMailComposer()
composer.present(self, subject:SV.s.report_user_title, body:SV.s.report_user_body)
}
class SVMailComposer: MFMailComposeViewController, MFMailComposeViewControllerDelegate {
func present(controller: UIViewController, subject: String, body: String) {
if MFMailComposeViewController.canSendMail() {
mailComposeDelegate = self
setToRecipients(["leo@superarts.org"])
setSubject(subject)
setMessageBody(body, isHTML: false)
controller.presentViewController(self, animated:true, completion:nil)
} else {
SV.show_text(SV.s.no_email)
}
}
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
if result.value == MFMailComposeResultCancelled.value {
SV.show_text(SV.s.cancelled)
} else if result.value == MFMailComposeResultSaved.value {
SV.show_text(SV.s.draft_saved)
} else if result.value == MFMailComposeResultSent.value {
SV.show_text(SV.s.report_sent)
} else if result.value == MFMailComposeResultFailed.value {
SV.show_text(SV.s.report_failed)
}
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment