Trying to send images picked from gallery ios then sending as attachments in email
@IBAction func loadImageButtonTappedGallery(_ sender: Any) {
imagePicker.allowsEditing = false
imagePicker.sourceType = .photoLibrary
imagePicker.modalPresentationStyle = UIModalPresentationStyle.currentContext
imagePicker.delegate = self
present(imagePicker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:
[UIImagePickerController.InfoKey : Any]) {
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
imageView.contentMode = .scaleAspectFit
imageView.image = pickedImage
}
dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
I've tried to set as UIImage as follows to pick 1 single image from gallery
let pickImage: NSData = UIImage.pngData()! as NSData
mail.addAttachmentData(pickImage as Data, mimeType: "image/png", fileName: "imageName.png")
self.present(mc, animated: true, completion: nil)
This fails: (pngData())
Instance member 'pngData' cannot be used on type 'UIImage'; did you mean to use a value of this type instead?