gpt4 book ai didi

来自自定义框架的 Swift 电子邮件失败

转载 作者:行者123 更新时间:2023-11-30 13:32:48 29 4
gpt4 key购买 nike

我制作了一个自定义框架(Swift),我在几个不同的应用程序中使用它。

我在此框架中添加的一项功能是基本电子邮件客户端。

代码如下,但它当前描述了以下行为:

最初完美加载电子邮件页面 View ,所有字段均按我期望的方式显示(即地址、密件抄送、主题、附件等),但是当我按发送或取消时,应用程序崩溃。但它实际上发送了电子邮件。我已经在“public func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?)”中打印了一个打印内容,但从未打印过。

请参阅下面的代码:

框架

import UIKit
import MessageUI


public class Framework_Email : NSObject, MFMailComposeViewControllerDelegate{

var picker : MFMailComposeViewController!

public var EmailSubject : String = ""
public var EmailMessage : String = ""
public var EmailAddress : [String] = []
public var EmailBlindAddress : [String] = []
public var EmailAttachment : [NSDictionary] = []

public func SendEmail(View : UIViewController)
{
picker = MFMailComposeViewController()
picker.mailComposeDelegate = self
picker.setToRecipients(EmailAddress)
picker.setSubject(EmailSubject)
picker.setMessageBody(EmailMessage, isHTML: false)
picker.setBccRecipients(EmailBlindAddress)

for temp in EmailAttachment
{
picker.addAttachmentData(temp["Data"] as! NSData, mimeType: temp["Type"] as! String, fileName: temp["Name"]as! String)
}
View.presentViewController(picker, animated: true, completion: nil)
}

public func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
print("Im Here!!!!!") //This is never seen in the output
picker.dismissViewControllerAnimated(true, completion: nil)
}
}

我在主应用程序 View Controller 中通过以下方式调用它

let EmailClient : Framework_Email = Framework_Email()
EmailClient.EmailAddress = ["email@eailaddress.co.uk"]
EmailClient.EmailMessage = "Email Message"
EmailClient.EmailSubject = "Email Subject"
EmailClient.EmailBlindAddress = ["email@eailaddress.co.uk"]
EmailClient.SendEmail(self)

谁能告诉我为什么这行不通?

谢谢

最佳答案

在您的关闭方法中使用 Controller 而不是选择器:

public func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) { 
print("Im Here!!!!!") //This is never seen in the output
controller.dismissViewControllerAnimated(true, completion: nil)
}

关于来自自定义框架的 Swift 电子邮件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36387888/

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