简体   繁体   English

Swift错误:“MailCompositionService意外退出”

[英]Swift error: “MailCompositionService quit unexpectedly”

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. 当我点击段落中的“点击此处”按钮时,如果您忘记了用户名/密码, 请点击此处将包含您的用户名/密码的验证邮件发送到您的电子邮件地址“,弹出对话框并说” MailCompositionService意外退出“,该消息是我想要解决的错误。

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. 这句话下面的这个类是具有“单击此处”按钮的页面的Swift代码,该按钮生成我想要解决的错误。 It is the ViewController class. 它是ViewController类。

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(["nurdin@gmail.com"])
        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 这是AppDelegate类

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. 编辑#2:我会发布更多故事板链接的截图,但我只能发布两个,所以请告诉我,我会给他们发电子邮件。

The MailCompositionService quit unexpectedly error is a simulator bug. MailCompositionService quit unexpectedly错误是模拟器错误。 Run your mail sending code on a real device to test it. 在真实设备上运行您的邮件发送代码以进行测试。

这是模拟器问题不是你的问题,尝试使用USB连接你的iPhone并从Xcode中选择然后运行应用程序,它应该没有错误,如果有错误让我们知道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM