Skip to content

Instantly share code, notes, and snippets.

@ProgramAlgo
Last active May 13, 2016 09:44
Show Gist options
  • Save ProgramAlgo/53d4a74532fb3d4d29898110f610c4f5 to your computer and use it in GitHub Desktop.
Save ProgramAlgo/53d4a74532fb3d4d29898110f610c4f5 to your computer and use it in GitHub Desktop.
MFMailComposeViewController and mustache
{{#messagebodys}}
<p><a href= "{{href}}">{{linktext}}</a></p>
{{/messagebodys}}
@IBAction func ExportBtnAction(sender: UIButton) {
if let messageBody = getMessageBody() {
let emailTitle = "Email Title "
// let toRecipents = [""]
let mc = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: true)
// mc.setToRecipients(toRecipents)
presentViewController(mc, animated: true, completion: nil)
}
}
func getMessageBody() -> String? {
var rendering: String? = nil
if let indexPaths = favTableView.indexPathsForSelectedRows {
let template = templateRegister("mail")
let messagebodys = indexPaths.map { (indexPath) -> [String: String!] in
let cell: FavoriteTableViewCell = favTableView.cellForRowAtIndexPath(indexPath)
as! FavoriteTableViewCell
return ["linktext": cell.subText, "href": cell.subText]
}
rendering = try! template.render(Box(["messagebodys": Box(messagebodys)]))
}
return rendering
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment