1

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)
Community
  • 1
  • 1
Charlie
  • 170
  • 12
  • Hi rmaddy, I thought I did append the pdfFileName to documentsPath by creating using the documentsPath.stringByAppendingPathComponent(fileName + ".pdf"). Then I passed it to fileData. Is that not the way? If not, is it meant to look something like this?... let documentsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).stringByAppendingPathComponent(fileName + ".pdf") – Charlie Apr 04 '16 at 20:30
  • My mistake. I looked at your code incorrectly. – rmaddy Apr 04 '16 at 20:41
  • no worries.. will just keep waiting to see if anyone else has any ideas.. thanks you for your help though... =) – Charlie Apr 05 '16 at 01:44

0 Answers0