gpt4 book ai didi

ios - 如何从 UI 标签(Swift 2 IOS 9)在应用程序中发送电子邮件?

转载 作者:行者123 更新时间:2023-11-28 06:52:15 26 4
gpt4 key购买 nike

附操纵本教程http://www.raywenderlich.com/113772/uisearchcontroller-tutorial

我有一个显示人物的 TableView ,当单击该单元格时,用户将被重定向到另一个显示他们的照片和电子邮件的 View 。 我希望能够让用户点击电子邮件地址并向他们发送电子邮件。我已经研究并找到了类似的教程 https://www.andrewcbancroft.com/2014/08/25/send-email-in-app-using-mfmailcomposeviewcontroller-with-swift/

上面教程的问题是当测试运行新代码时,ios 模拟器会弹出一个错误并且不会显示撰写的电子邮件(也许是一个小故障?)如果模拟器没有给出错误我不知道如何显示根据用户选择的人发送多封电子邮件。任何有关解决此问题或任何替代方案的帮助都将非常感谢!!

最佳答案

当您尝试打开邮件时,模拟器会崩溃。请改为在实际设备上尝试。

要撰写邮件,请执行以下操作将这些添加到您的类(class)MFMessageComposeViewControllerDelegateMFMailComposeViewControllerDelegate

在您的 didSelectRowAtIndexPath 中,这是在您按下 tableView 中的一行时调用的函数。执行以下操作:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
let candy = candies[indexPath.row]
var mail: MFMailComposeViewController!

// yourArray is the array that you use to populate the tableView
// .mail is the variable in the object (I´m assuming you´re using objects in your array)
let toRecipients = [candy[indexPath.row].email]
let subject = "Feedback"
let body = "<br><br><p>I have a \(UIDevice.currentDevice().modelName).<br> And iOS version \(UIDevice.currentDevice().systemVersion).<br</p>"

mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(toRecipients)
mail.setSubject(subject)
mail.setMessageBody(body, isHTML: true)

presentViewController(mail, animated: true, completion: nil)
}

下面的委托(delegate)方法如果你需要使用它们

func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
dismissViewControllerAnimated(true, completion: nil)
}

func messageComposeViewController(controller: MFMessageComposeViewController, didFinishWithResult result: MessageComposeResult) {
switch (result.rawValue) {
case MessageComposeResultCancelled.rawValue:
self.dismissViewControllerAnimated(true, completion: nil)
case MessageComposeResultFailed.rawValue:
self.dismissViewControllerAnimated(true, completion: nil)
case MessageComposeResultSent.rawValue:
self.dismissViewControllerAnimated(true, completion: nil)
default:
break;
}
}

关于ios - 如何从 UI 标签(Swift 2 IOS 9)在应用程序中发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34570770/

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