我正在尝试使用MFMailComposeViewControllerDelegate
使用以下代码设置电子邮件视图控制器:
let fileName = "test.csv"
let path = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)
if MFMailComposeViewController.canSendMail() {
let emailController = MFMailComposeViewController()
emailController.mailComposeDelegate = self
emailController.setToRecipients(["testemail.com"])
emailController.setSubject("Test Email")
emailController.setMessageBody("Test Message", isHTML: false)
emailController.addAttachmentData(NSData(contentsOfURL: path)!, mimeType: "text/csv", fileName: "test.csv")
present(emailController, animated: true, completion: nil)
}
上述内容在error
行上发出addAttachmentData
,
在没有更多上下文的情况下,表达式的类型不明确。
我错过了什么吗?
答案 0 :(得分:1)
使用两个表达式而不是一个:
let data = Data(contentsOf: path)!
emailController.addAttachmentData(data, mimeType: "text/csv", fileName: "test.csv")