错误消息截图:
当我点击"点击此处"段落中的按钮显示"如果您忘记了用户名/密码,点击此处将包含您的用户名/密码的验证邮件发送到您的电子邮件地址",弹出对话框并且说" MailCompositionService意外退出",该消息是我想要解决的错误。
这句话下面的这个类是具有"点击此处的页面的Swift代码"生成我想要解决的错误的按钮。它是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)
}
}
这是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
}
}
创建帐户页面:
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
}
编辑:我还包括两个截图,所以请查看它们以明确说明。 编辑#2:我会发布更多故事板链接的截图,但我只能发布两个,所以请告诉我,我会给他们发电子邮件。
答案 0 :(得分:7)
MailCompositionService quit unexpectedly
错误是模拟器错误。在真实设备上运行您的邮件发送代码以进行测试。
答案 1 :(得分:1)
这是模拟器问题不是你的问题,尝试使用USB连接你的iPhone并从Xcode中选择然后运行应用程序,它应该没有错误,如果有错误让我们知道