Guest User

Untitled

a guest
Jan 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import MessageUI
  2. class ProfileVC: UsernameVC, MFMailComposeViewControllerDelegate {
  3.  
  4. @IBOutlet weak var emailButtonLabel: UIButton!
  5.  
  6. @IBOutlet weak var attenDescrip: UITextView!
  7.  
  8. override func viewDidLoad() {
  9. //super.viewDidLoad()
  10.  
  11. }
  12.  
  13. @IBAction func emailPressed(_ sender: Any) {
  14. print("email pressed")
  15. let mailCOmposevViewController = configureMailController()
  16. if MFMailComposeViewController.canSendMail(){
  17. self.present(mailCOmposevViewController, animated: true, completion: nil)
  18. }
  19. else {
  20. showMailError()
  21. }
  22. }
  23.  
  24. func configureMailController() -> MFMailComposeViewController {
  25. let mailCOmposerVC = MFMailComposeViewController()
  26. mailCOmposerVC.mailComposeDelegate = self
  27. mailCOmposerVC.setToRecipients(["first@gmail.com"])
  28. mailCOmposerVC.setSubject("Application")
  29. mailCOmposerVC.setMessageBody("app.", isHTML: false)
  30. return mailCOmposerVC
  31.  
  32. }
  33. func showMailError() {
  34. let sendMailErrorAlert = UIAlertController(title: "Could not send email", message: "Please set up your email account", preferredStyle: .alert)
  35. let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
  36. sendMailErrorAlert.addAction(dismiss)
  37. self.present(sendMailErrorAlert, animated: true, completion: nil)
  38. }
  39. func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
  40. controller.dismiss(animated: true, completion: nil)
  41. }
  42. }
Add Comment
Please, Sign In to add comment