将CollectionViewView照片传递给电子邮件附件iOS swift
我从照片库中select了一些照片,并填充到collectionView中。 那么我的collections视图里面会有一些照片。 这里是我的代码获取照片到collections视图。
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 }
但是,如何将位于集合视图中的所有这些照片传递给电子邮件附件? 下面的代码是电子邮件附件,我如何将所有的照片传递给这个附件?
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
,您可以获取所有这些图像,并附加到邮件中。 或者如果你想附加所有的图像,那么你可以将所有加载的图像添加到一个数组,并附加这些邮件,如:
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添加到邮件编辑器中
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) }
- 如何检测任意string中的电子邮件地址
- 不能通过点击UITextVIew中的邮件链接显示MFMailComposeViewController(iOS 8 beta bug)
- iOS >> ShareKit >>select所需的共享服务
- MFMailComposeViewController将签名附加为.txt文件
- Xcode 4 / iOS – 从我的应用程序内使用SMTP发送电子邮件
- HTML邮件中的尴尬超链接生成
- 我如何在Linux上构build一个Mac包? (BOM文件问题)
- MFMailComposeViewController电子邮件到iPhone的字段限制40
- iOS – 将联系人添加到联系人?