发送多张图像作为附件

时间:2019-07-15 21:30:07

标签: swift email-attachments

尝试发送从Gallery ios拾取的图像,然后以电子邮件附件的形式发送

@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)
}

我已尝试将UIImage设置为如下,以从图库中选择1张单张图片

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)

此操作失败:(pngData())

  

实例成员'pngData'不能用于'UIImage'类型;您是不是要使用这种类型的值?

0 个答案:

没有答案