|
@@ -822,23 +822,31 @@ public class Nexilis: NSObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static func openmailAction() {
|
|
|
- if let googleUrl = NSURL(string: "googlegmail://"), UIApplication.shared.canOpenURL(googleUrl as URL) {
|
|
|
- openMail(googleUrl)
|
|
|
- } else if let mailURL = NSURL(string: "message://"), UIApplication.shared.canOpenURL(mailURL as URL) {
|
|
|
- openMail(mailURL)
|
|
|
- } else if let outlookURL = NSURL(string: "ms-outlook://"), UIApplication.shared.canOpenURL(outlookURL as URL) {
|
|
|
- openMail(outlookURL)
|
|
|
- } else if let yahooURL = NSURL(string: "ymail://"), UIApplication.shared.canOpenURL(yahooURL as URL) {
|
|
|
- openMail(yahooURL)
|
|
|
- } else if let sparkUrl = NSURL(string: "readdle-spark://"), UIApplication.shared.canOpenURL(sparkUrl as URL) {
|
|
|
+ static func openmailAction(subject: String = "", body: String = "", to: String = "") {
|
|
|
+ let subjectEncoded = subject.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
|
|
|
+ let bodyEncoded = body.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
|
|
|
+ let toEmail = to
|
|
|
+
|
|
|
+ let gmailUrl = URL(string: "googlegmail://co?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
|
|
|
+ let outlookUrl = URL(string: "ms-outlook://compose?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
|
|
|
+ let yahooMail = URL(string: "ymail://mail/compose?to=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
|
|
|
+ let sparkUrl = URL(string: "readdle-spark://compose?recipient=\(toEmail)&subject=\(subjectEncoded)&body=\(bodyEncoded)")!
|
|
|
+ let defaultUrl = URL(string: "mailto:\(toEmail)?subject=\(subjectEncoded)&body=\(bodyEncoded)")!
|
|
|
+
|
|
|
+ if UIApplication.shared.canOpenURL(gmailUrl as URL) {
|
|
|
+ openMail(gmailUrl)
|
|
|
+ } else if UIApplication.shared.canOpenURL(outlookUrl as URL) {
|
|
|
+ openMail(outlookUrl)
|
|
|
+ } else if UIApplication.shared.canOpenURL(yahooMail as URL) {
|
|
|
+ openMail(yahooMail)
|
|
|
+ } else if UIApplication.shared.canOpenURL(sparkUrl as URL) {
|
|
|
openMail(sparkUrl)
|
|
|
- } else {
|
|
|
- // showAlert
|
|
|
+ } else if UIApplication.shared.canOpenURL(defaultUrl as URL) {
|
|
|
+ openMail(defaultUrl)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static func openMail(_ url: NSURL) {
|
|
|
+ private static func openMail(_ url: URL) {
|
|
|
UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
|
|
|
}
|
|
|
|