BSimagePicker选择图像到电子邮件附件

时间:2016-02-11 08:30:14

标签: ios swift image email attachment

我创建了一个简单的应用程序,需要将一些图片发送到特定的电子邮件。已经有了以下工作

拍照,选择图片(bsimagepicker),发送电子邮件按钮,为特定的电子邮件地址创建电子邮件。

现在我想将带有bsimagepicker的所选图像作为附件添加到电子邮件中。但现在当我按完了应用程序忘记了所选图像。这是我用于BSimagepicker的代码。

@IBAction func showImagePicker(sender: UIButton) {
    let vc = BSImagePickerViewController()
    vc.maxNumberOfSelections = 10

    bs_presentImagePickerController(vc, animated: true,
        select: { (asset: PHAsset) -> Void in
            print("Selected: \(asset)")
        }, deselect: { (asset: PHAsset) -> Void in
            print("Deselected: \(asset)")
        }, cancel: { (assets: [PHAsset]) -> Void in
            print("Cancel: \(assets)")
        }, finish: { (assets: [PHAsset]) -> Void in
            print("Finish: \(assets)")
        }, completion: nil)


@IBAction func showCustomImagePicker(sender: UIButton) {
let vc = BSImagePickerViewController()
vc.maxNumberOfSelections = 10
vc.takePhotoIcon = UIImage(named: "chat")

vc.albumButton.tintColor = UIColor.greenColor()
vc.cancelButton.tintColor = UIColor.redColor()
vc.doneButton.tintColor = UIColor.purpleColor()
vc.selectionCharacter = "✓"
vc.selectionFillColor = UIColor.grayColor()
vc.selectionStrokeColor = UIColor.yellowColor()
vc.selectionShadowColor = UIColor.redColor()
vc.selectionTextAttributes[NSForegroundColorAttributeName] = UIColor.lightGrayColor()
vc.cellsPerRow = {(verticalSize: UIUserInterfaceSizeClass, horizontalSize: UIUserInterfaceSizeClass) -> Int in
    switch (verticalSize, horizontalSize) {
    case (.Compact, .Regular): // iPhone5-6 portrait
        return 2
    case (.Compact, .Compact): // iPhone5-6 landscape
        return 2
    case (.Regular, .Regular): // iPad portrait/landscape
        return 3
    default:
        return 2
    }
}

bs_presentImagePickerController(vc, animated: true,
    select: { (asset: PHAsset) -> Void in
        print("Selected: \(asset)")
    }, deselect: { (asset: PHAsset) -> Void in
        print("Deselected: \(asset)")
    }, cancel: { (assets: [PHAsset]) -> Void in
        print("Cancel: \(assets)")
    }, finish: { (assets: [PHAsset]) -> Void in
        print("Finish: \(assets)")
    }, completion: nil)

对于电子邮件,我使用以下代码:

mailComposerVC.setToRecipients(["jvanhattem@it-serve.nl"])
mailComposerVC.setSubject("Mail vanuit PicMail")
mailComposerVC.setMessageBody("Onderstaand de doorgestuurde informatie", isHTML: false)

if let image = imageView.image {
    let data = UIImageJPEGRepresentation(image, 1.0)
    mailComposerVC.addAttachmentData(data!, mimeType: "image/jpg", fileName: "image")
}

0 个答案:

没有答案