问题
I'm having problems getting this PDF document I created to attach to an email. So basically in my app I get the user to type in some text via a UITextfied
and then take that text and put in into a PDF document. I then want the user to be able to send this PDF as an email attachment when clicking a button. Any thoughts on where I went wrong attaching this pdf as a attachment?
I got this code from Attach a PDF file to email - Swift and I just modified it but still no attachment. Also its coming up with the error
stringByAppendingPathComponent is unavailable: Use URLByAppendingPathCompenent on NSURL instead.
Had a look at this stringByAppendingPathComponent is unavailable and it doesnt make sense to me sorry.
//find the file and the path
let fileName: String = self.tfEssayTopicTitle.text!
let documentsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as! String
let pdfFileName = documentsPath.stringByAppendingPathComponent(fileName + ".pdf")
let fileData = NSData(contentsOfFile: pdfFileName)
mailVC.addAttachmentData(fileData!, mimeType: "application/pdf", fileName: pdfFileName)
来源:https://stackoverflow.com/questions/36404234/pdf-document-wont-attach-to-ios-email