fix bugs in email developer function

This commit is contained in:
Bob Sun 2017-02-09 16:44:02 +08:00
parent 52b007866f
commit 1e07cf2e46
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
2 changed files with 7 additions and 5 deletions

View file

@ -14,7 +14,7 @@ class AboutTableViewController: BasicStaticTableViewController {
tableData = [ tableData = [
// section 0 // section 0
[[.type: CellDataType.link, .title: "Website", .link: "https://github.com/mssun/pass-ios.git"], [[.type: CellDataType.link, .title: "Website", .link: "https://github.com/mssun/pass-ios.git"],
[.type: CellDataType.link, .title: "Contact Developer", .link: "mailto:bob@mssun.me&subject=passforiOS"],], [.type: CellDataType.link, .title: "Contact Developer", .link: "mailto:bob@mssun.me?subject=passforiOS"],],
// section 1, // section 1,
[[.type: CellDataType.segue, .title: "Open Source Components", .link: "showOpenSourceComponentsSegue"], [[.type: CellDataType.segue, .title: "Open Source Components", .link: "showOpenSourceComponentsSegue"],

View file

@ -72,7 +72,9 @@ class BasicStaticTableViewController: UITableViewController, MFMailComposeViewCo
let url = URL(string: link)! let url = URL(string: link)!
switch url.scheme! { switch url.scheme! {
case "mailto": case "mailto":
sendEmail(toRecipients: [URLComponents(string: link)?.path ?? ""]) let urlComponents = URLComponents(string: link)!
let subject = urlComponents.queryItems![0].value ?? ""
sendEmail(toRecipients: [urlComponents.path], subject: subject)
case "http", "https": case "http", "https":
let svc = SFSafariViewController(url: URL(string: link)!, entersReaderIfAvailable: false) let svc = SFSafariViewController(url: URL(string: link)!, entersReaderIfAvailable: false)
self.present(svc, animated: true, completion: nil) self.present(svc, animated: true, completion: nil)
@ -84,12 +86,12 @@ class BasicStaticTableViewController: UITableViewController, MFMailComposeViewCo
} }
} }
func sendEmail(toRecipients recipients: [String]) { func sendEmail(toRecipients recipients: [String], subject: String) {
let mailVC = MFMailComposeViewController() let mailVC = MFMailComposeViewController()
mailVC.mailComposeDelegate = self mailVC.mailComposeDelegate = self
mailVC.setToRecipients(recipients) mailVC.setToRecipients(recipients)
mailVC.setSubject("Subject for email") mailVC.setSubject(subject)
mailVC.setMessageBody("Email message string", isHTML: false) mailVC.setMessageBody("", isHTML: false)
self.present(mailVC, animated: true, completion: nil) self.present(mailVC, animated: true, completion: nil)
} }