Created
June 29, 2015 14:15
-
-
Save superarts/b10c3997ddb62b97a155 to your computer and use it in GitHub Desktop.
Simple Mail Composer in Swift
This file contains hidden or 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
@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(["[email protected]"]) | |
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