Reputation: 676
I am new to IOS programming so I'm not sure if this is a staple of programming or something complex, but I would like to add a feedback feature to my application. That is, I am thinking of having a button called "FeedBack", that, when the user clicks on it, redirects them to their native email application with the 'to' section already filled with my credentials. Any advice on how I can do that?
Upvotes: 1
Views: 788
Reputation: 4470
Just for your information you cannot send mail from simulator so it gives error which handled here try the following code
import Foundation
import MessageUI
import UIKit
class test: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if MFMailComposeViewController.canSendMail()
{
sendEmail()
}
else
{
print("Mail services are not available")
return
}
}
func sendEmail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
composeVC.setToRecipients(["[email protected]"])
composeVC.setSubject("Any subject!")
composeVC.setMessageBody("this is your message body!", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
controller.dismiss(animated: true, completion: nil)
}
}
Upvotes: 2