簡體   English   中英

Swift 3發送帶有附件歧義表達的電子郵件

[英]Swift 3 Send Email with Attachment Ambiguous Expression

我正在嘗試使用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)
        }

上面在addAttachmentData行上拋出了一個error

沒有更多上下文的情況下,表達類型不明確。

我想念什么嗎?

使用兩個表達式而不是一個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM