2016-01-26 48 views
-1

好吧,我现在进一步了。我收到了在应用程序中工作的电子邮件按钮,但它并没有添加我在电子邮件的UIImageview中选择的图片。有人能告诉我如何将选中的图片添加到电子邮件正文中吗?发送电子邮件附带图片视图

@IBAction func FotoKnop(sender: AnyObject) { 
} 

@IBAction func chooseImageFromPhotoLibrary() { 
    let picker = UIImagePickerController() 

    picker.delegate = self 
    picker.sourceType = .PhotoLibrary 

    presentViewController(picker, animated: true, completion: nil) 
} 

@IBAction func chooseFromCamera() { 
    let picker = UIImagePickerController() 

    picker.delegate = self 
    picker.sourceType = .Camera 

    presentViewController(picker, animated: true, completion: nil) 
} 
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { 
    imageView.image = image 
    self.dismissViewControllerAnimated(true, completion: nil) 
} 
    // start e-mail 

    @IBAction func sendEmailButtonTapped(sender: AnyObject) { 
     let mailComposeViewController = configuredMailComposeViewController() 
     if MFMailComposeViewController.canSendMail() { 
      self.presentViewController(mailComposeViewController, animated: true, completion: nil) 
     } else { 
     } 
    } 

    func configuredMailComposeViewController() -> MFMailComposeViewController { 
     let mailComposerVC = MFMailComposeViewController() 
     mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property 
     mailComposerVC.setToRecipients(["[email protected]"]) 
     mailComposerVC.setSubject("Mail vanuit PicMail") 
     mailComposerVC.setMessageBody("Onderstaand de doorgestuurde informatie", isHTML: 
      false) 

     return mailComposerVC 
    } 

    func showSendMailErrorAlert() { 
     let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK") 
     sendMailErrorAlert.show() 
    } 

    // MARK: MFMailComposeViewControllerDelegate Method 
    func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) { 
     controller.dismissViewControllerAnimated(true, completion: nil) 
    } 
} 
+0

给我反馈,如果它的工作.. – Anokrize

+0

Anokrize,感谢您的意见。当我实现你的代码我得到2行错误:func configuredMailComposeViewController() - > MFMailComposeViewController {(如果MFMailComposeViewController.canSendMail(){。它说使用未声明的类型MFmailComposeViewController。 –

+0

看看上面的导入是否实现了它们? – Anokrize

回答

0

试试这个代码皮毛您的电子邮件功能:

func configuredMailComposeViewController() -> MFMailComposeViewController { 
    let mailComposerVC = MFMailComposeViewController() 
    mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property 

    mailComposerVC.setToRecipients(["[email protected]"]) 
    mailComposerVC.setSubject("Sending you an in-app e-mail...") 
    mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false) 

    return mailComposerVC 
} 

而这种代码在你的动作功能或你想添加的位置...

let mailComposeViewController = configuredMailComposeViewController() 
    if MFMailComposeViewController.canSendMail() { 
     // On Success 
    } else { 
     // Error handling here 
    } 
相关问题