Swift 3发送带附件歧义表达的电子邮件

时间:2017-07-06 03:28:04

标签: swift

我正在尝试使用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

  

在没有更多上下文的情况下,表达式的类型不明确。

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

使用两个表达式而不是一个:

    let data = Data(contentsOf: path)!
 emailController.addAttachmentData(data, mimeType: "text/csv", fileName: "test.csv")