将CollectionView照片传递给iOS电子邮件附件 [英] Pass CollectionView photo to Email Attachment iOS swift

查看:92
本文介绍了将CollectionView照片传递给iOS电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从照片库中选择了一些照片,并填充到collectionView中。然后,我的收藏视图中将包含一些照片。
这是我将照片放入收藏夹视图的代码。

I've choose some photo from the photo library and populated into the collectionView. Then my collection view will have some photos inside. Here is my code for getting the photos into collection view.

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell: PhotoCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("PhotoCell", forIndexPath: indexPath) as! PhotoCollectionViewCell
    let asset : PHAsset = self.photoAsset[indexPath.item] as! PHAsset
    PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: PHImageManagerMaximumSize, contentMode: .AspectFill, options: nil, resultHandler: {(result, info)in
        if let image = result
        {
            cell.setThumbnailImage(image)
        }
    })
    return cell
}

但是,如何将收藏夹视图中的所有这些照片传递给电子邮件附件?下面的代码是电子邮件附件,如何将所有照片传递到该附件中?

However, how do I pass all these photo which are located in the collection View to the email attachment? Below code is the email attachment, how do I pass all the photos into this attachment?

let emailTitle = "Email Us"
let messageBody = "Location: \(sendLocation) \n\n \(sendContent)"
let toReceipients = ["testing@gmail.com"]
let mc : MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
mc.setToRecipients(toReceipients)
self.presentViewController(mc, animated: true, completion: nil)


推荐答案

以相同的方式从中获取图像,您可以获取 PHImageManager ,您可以获取所有此类图像并仅附加到邮件中。
或者,如果要附加所有图像,则可以将所有已加载的图像添加到数组中,然后将其附加到邮件中,例如:

The same way you get the image from the you can get the PHImageManager, you can get all such images and just attach to mail. Or if you want to attach ALL images, then you can add all the loaded images to an array and attach those to mail like:

let asset : PHAsset = self.photoAsset[indexPath.item] as! PHAsset
    PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: PHImageManagerMaximumSize, contentMode: .AspectFill, options: nil, resultHandler: {(result, info)in
        if let image = result
        {
            cell.setThumbnailImage(image)
            self.arr.append(image)
        }
    })

然后将arr中的所有图像添加到邮件编辑器中,例如

Then add all the images from the arr to mail composer, like

func composeMail() {
        let mailComposeVC = MFMailComposeViewController()

        for image in arr {
                let photoData : NSData = UIImagePNGRepresentation(image)!
                mailComposeVC.addAttachmentData(UIImageJPEGRepresentation(photoData, CGFloat(1.0))!, mimeType: "image/jpeg", fileName:  "test.jpeg")   
        }
        mailComposeVC.setSubject("Email Subject")
        self.presentViewController(mailComposeVC, animated: true, completion: nil)

    }

这篇关于将CollectionView照片传递给iOS电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆