gpt4 book ai didi

ios - 在 Swift 中发送应用程序电子邮件

转载 作者:行者123 更新时间:2023-11-28 13:17:53 26 4
gpt4 key购买 nike

在 Swift 中执行此操作时遇到问题。在 Objective C 中非常容易。我在日志中得到的错误是这样的:

2015-01-31 22:16:58.734 fun facts[15208:623304] Unknown class Settings in Interface Builder file.
2015-01-31 22:17:10.783 fun facts[15208:623304] -[UIViewController sendEmail:]: unrecognized selector sent to instance 0x7f9b7bc2fa30
2015-01-31 22:17:10.794 fun facts[15208:623304] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController sendEmail:]: unrecognized selector sent to instance 0x7f9b7bc2fa30'

请参阅下面的代码。知道我做错了什么吗?

//////////////////////SEND EMAIL


@IBAction func sendEmail(sender: AnyObject) {

var emailTitle = "Test Email"
var messageBody = "This is a test email body"
var toRecipents = ["yolo@mail.com"]
var mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
mc.setToRecipients(toRecipents)

self.presentViewController(mc, animated: true, completion: nil)
}



func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) {
switch result.value {
case MFMailComposeResultCancelled.value:
println("Mail cancelled")
case MFMailComposeResultSaved.value:
println("Mail saved")
case MFMailComposeResultSent.value:
println("Mail sent")
case MFMailComposeResultFailed.value:
println("Mail sent failure: \(error.localizedDescription)")
default:
break
}
self.dismissViewControllerAnimated(false, completion: nil)
}

}

最佳答案

如果您不小心将 View 的类设置为不兼容的自定义类,就会发生这种错误;例如,不小心将 UIButton 的自定义类设置为“Settings”,即本例中的 UIViewController 类,可能会导致您的特定错误。

关于ios - 在 Swift 中发送应用程序电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28256995/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com