send email to contact developer

This commit is contained in:
Bob Sun 2017-02-09 16:33:39 +08:00
parent 95de38988b
commit b97500ed1e
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
2 changed files with 28 additions and 4 deletions

View file

@ -8,6 +8,8 @@
import UIKit
import SafariServices
import MessageUI
enum CellDataType {
case link, segue, empty
@ -17,7 +19,7 @@ enum CellDataKey {
case type, title, link, footer, accessoryType, detailDisclosureAction, detailDisclosureData
}
class BasicStaticTableViewController: UITableViewController {
class BasicStaticTableViewController: UITableViewController, MFMailComposeViewControllerDelegate {
var tableData = [[Dictionary<CellDataKey, Any>]]()
var navigationItemTitle: String?
@ -67,10 +69,32 @@ class BasicStaticTableViewController: UITableViewController {
performSegue(withIdentifier: link!, sender: self)
case .link:
let link = cellData[CellDataKey.link] as! String
let svc = SFSafariViewController(url: URL(string: link)!, entersReaderIfAvailable: false)
self.present(svc, animated: true, completion: nil)
let url = URL(string: link)!
switch url.scheme! {
case "mailto":
sendEmail(toRecipients: [URLComponents(string: link)?.path ?? ""])
case "http", "https":
let svc = SFSafariViewController(url: URL(string: link)!, entersReaderIfAvailable: false)
self.present(svc, animated: true, completion: nil)
default:
break
}
default:
break
}
}
func sendEmail(toRecipients recipients: [String]) {
let mailVC = MFMailComposeViewController()
mailVC.mailComposeDelegate = self
print(recipients)
mailVC.setToRecipients(recipients)
mailVC.setSubject("Subject for email")
mailVC.setMessageBody("Email message string", isHTML: false)
self.present(mailVC, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
}