0

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
sac23
  • 1
  • 2
  • 1. Don't use `NSData`. Use `Data`. 2. Cal `pngData()` on a specific instance of `UIImage`. – rmaddy Jul 15 '19 at 21:34
  • Possible duplicate of [Compress Image in iOS 12. How will this code be updated?](https://stackoverflow.com/questions/52116351/compress-image-in-ios-12-how-will-this-code-be-updated) – rmaddy Jul 15 '19 at 21:35

0 Answers0