2016-01-26 78 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 
    } 
相關問題