Mako Shan

Mako 是一名密码朋克爱好者
这里是我记录生活和成长的地方

联系我的微信号
👏欢迎一起交流学习

iOS9调用系统邮箱,发邮件

首先导入 import MessageUI
然后要继承 MFMailComposeViewControllerDelegate

@IBAction func email(sender: AnyObject) {
        UIApplication.sharedApplication().keyWindow?.endEditing(true)
        var configuredMailComposeViewController = MailComposeViewController()
        if canSendMail() {
            presentViewController(configuredMailComposeViewController, animated: true, completion: nil)
        } else {
            showSendMailErrorAlert()
        }
    }

    func MailComposeViewController() -> MFMailComposeViewController {
        let mailComposerVC                 = MFMailComposeViewController()
        mailComposerVC.mailComposeDelegate = self

        mailComposerVC.setToRecipients(nil)
        mailComposerVC.setSubject(nil)
        mailComposerVC.setMessageBody(self.textview.text, isHTML: false)
        var addPic                         = self.madelongPicture()
        var imageData                      = UIImagePNGRepresentation(addPic)
        mailComposerVC.addAttachmentData(imageData, mimeType: "", fileName: "longPicture.png")
        return mailComposerVC
    }
    func canSendMail() -> Bool {
        return MFMailComposeViewController.canSendMail()
    }
    func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
        controller.dismissViewControllerAnimated(true, completion: nil)
    }
    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()
    }
0
iOS程序卡在安装中
目录