Add a photo to MailComposer Swift

25 Views Asked by At

I created an app that, with a button allows you to choose between taking a photo with the camera or picking it from the library (UIImagePickerController). When you choose the photo, then it is assigned to an ImageView. With another button I want the user to be able to compose a mail using MailComposer that is already pre-compiled (recipient, subject and message body). I also want to attach the image assigned to the web view, and I tried with this code

mailComposerVC.addAttachmentData(UIImageJPEGRepresentation(UIImage(named: "emailImage")!, CGFloat(1.0))!, mimeType: "image/jpeg", fileName:  "image")

But it doesn't work, with this error "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"

Thank you!

0

There are 0 best solutions below