Reputation: 31
The error message screenshot:
When I click the "click here" button in the paragraph that says "If you forgot your username/password, click here to send a verification message that contains your username/password to your email address", the dialogue box pops up and says "MailCompositionService quit unexpectedly", and that message is the error I want to solve.
This class below this sentence is the Swift code for the page that has the "click here" button which generates the error I want to solve. It is the ViewController class.
import UIKit
import MessageUI
class ViewController: UIViewController, MFMailComposeViewControllerDelegate
{
@IBOutlet weak var ClickHereSendEmailButton: UIButton!
@IBOutlet weak var Label: UILabel!
@IBOutlet weak var UsernameTextField: UITextField!
@IBOutlet weak var PasswordTextField: UITextField!
@IBOutlet weak var SignInButton: UIButton!
@IBAction func PressedSignInButton(sender: UIButton)
{
if UsernameTextField.text == username && PasswordTextField.text == password
{
// create the alert
let alert = UIAlertController(title: "Correct", message: "Your credentials are correct.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
Label.text = "The credentials are correct."
UsernameTextField.resignFirstResponder()
PasswordTextField.resignFirstResponder()
}
else
{
// create the alert
let alert = UIAlertController(title: "Incorrect", message: "Your credentials are incorrect.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
Label.text = "The credentials are not correct."
UsernameTextField.resignFirstResponder()
PasswordTextField.resignFirstResponder()
}
}
@IBAction func PressedClickHereSendEmailButton(sender: UIButton)
{
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["[email protected]"])
mailComposerVC.setSubject("Sending you an in-app e-mail...")
mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
Here is the AppDelegate class
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
}
Create account page:
import UIKit
var username = ""
var password = ""
var email = ""
class CreateAccountPage: UIViewController
{
@IBOutlet weak var UserNameTextField: UITextField!
@IBOutlet weak var PasswordTextField: UITextField!
@IBOutlet weak var EmailAddressTextField: UITextField!
@IBOutlet weak var ActivateButton: UIButton!
@IBOutlet weak var ReturnButton: UIButton!
@IBAction func PressedActivateButton(sender: UIButton)
{
username = UserNameTextField.text!
password = PasswordTextField.text!
email = EmailAddressTextField.text!
// create the alert
let alert = UIAlertController(title: "Activated", message: "Your new account is now activated.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
}
@IBAction func ReturnButton(sender: UIButton)
{
}
//performSegueWithIdentifier("mySegueID", sender: nil
}
EDIT: I also included two screenshots so please view them to make it clear. EDIT #2: I would post more screenshots of the storyboard links but I can only post two, so let me know and I'll email them.
Upvotes: 2
Views: 1255
Reputation: 445
This is simulator problem not your problem , Try to connect your iPhone using usb and select it from Xcode then run the application , it should work without error , if there is an errors let us know
Upvotes: 1
Reputation: 40028
The MailCompositionService quit unexpectedly
error is a simulator bug. Run your mail sending code on a real device to test it.
Upvotes: 7