Created
December 12, 2018 06:01
-
-
Save leoiphonedev/eab2f6357ceba78b36003a9b9191468c to your computer and use it in GitHub Desktop.
COnformimng to MFMailComposeViewControllerDelegate so that we get notified on user certain action with mail composer view
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
import UIKit | |
import MessageUI | |
class ViewController: UIViewController, MFMailComposeViewControllerDelegate { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
@IBAction func sendEmail(_ sender: Any) { | |
if MFMailComposeViewController.canSendMail() { | |
let mailComposer = MFMailComposeViewController() | |
mailComposer.setSubject("Update about ios tutorials") | |
mailComposer.setMessageBody("What is the update about ios tutorials on youtube", isHTML: false) | |
mailComposer.setToRecipients(["[email protected]"]) | |
mailComposer.mailComposeDelegate = self | |
self.present(mailComposer, animated: true | |
, completion: nil) | |
} else { | |
print("Email is not configured in settings app or we are not able to send an email") | |
} | |
} | |
//MARK:- MailcomposerDelegate | |
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { | |
switch result { | |
case .cancelled: | |
print("User cancelled") | |
break | |
case .saved: | |
print("Mail is saved by user") | |
break | |
case .sent: | |
print("Mail is sent successfully") | |
break | |
case .failed: | |
print("Sending mail is failed") | |
break | |
default: | |
break | |
} | |
controller.dismiss(animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment