UIActivityViewController发送UIImage

时间:2018-08-06 14:49:22

标签: swift uiimage uiactivityviewcontroller

我在App中生成了一张图片

uiimageview中显示的图像

这是我的图片

var img:UIImage!
img = UIImage(ciImage: transformedImage)

这是在断点处共享之前的值

print(img)

some(UIImage:12345,{200,200})

let myShare = "My beautiful photo! <3 <3"


let shareVC: UIActivityViewController = UIActivityViewController(activityItems: [(img), myShare], applicationActivities: nil)
self.present(shareVC, animated: true, completion: nil)

但是无法显示图像,但是只能在iMessage或电子邮件和其他应用程序中显示图像的文本...如何共享图像?在iMessage电子邮件等中

1 个答案:

答案 0 :(得分:0)

使用此方法:

func shareImageBtn(img : UIImage, txt : String) {
// if an image and a txt aren't nil
        let resourses = [ image!, txt!]
        let activityViewController = UIActivityViewController(activityItems: resources, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view // iPads won't crash

        // (optional)
        activityViewController.excludedActivityTypes = [ .airDrop, .postToFacebook ]

        // present the VC
        self.present(activityViewController, animated: true, completion: nil)
    }