Commit 339c720e by Demid Merzlyakov

Menu Help: if the default Mail app is not configured, try to open a mailto: URL…

Menu Help: if the default Mail app is not configured, try to open a mailto: URL instead of showing the error right away.
parent 840a9fcf
......@@ -151,13 +151,6 @@ extension MenuViewModel {
}
public func showHelp() {
if !MFMailComposeViewController.canSendMail() {
let alertView = UIAlertController(title: nil, message: "menu.help.unableToSendEmail.text".localized(), preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "general.ok".localized(), style: .default, handler: nil))
self.viewControllerForPresentation().present(alertView, animated: true, completion: nil)
return
}
var emailSubject = ""
let emailBody = helpRequestBodyString()
var emailRecipients = [String]()
......@@ -178,15 +171,37 @@ extension MenuViewModel {
let installedDate = "Unknown"
let deviceInfo = "Version: \(version)-\(build)\nDevice: \(deviceName)\nOS: \(systemVersion)\nPro: \(isPro) \nInstalled: \(installedDate) \(deviceToken)"
let emailHeaderAndBody = "\(deviceInfo) \n\n\(emailBody)"
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.modalPresentationStyle = .formSheet
mc.setSubject(emailSubject)
mc.setMessageBody("\(deviceInfo) \n\n\(emailBody)", isHTML: false)
mc.setToRecipients(emailRecipients)
self.viewControllerForPresentation().present(mc, animated: true, completion: nil)
if MFMailComposeViewController.canSendMail() {
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.modalPresentationStyle = .formSheet
mc.setSubject(emailSubject)
mc.setMessageBody(emailHeaderAndBody, isHTML: false)
mc.setToRecipients(emailRecipients)
self.viewControllerForPresentation().present(mc, animated: true, completion: nil)
}
else {
let mailtoParams = [
"subject": emailSubject,
"body": emailHeaderAndBody
]
let mailtoQuery = mailtoParams.map { "\($0.key)=\($0.value)" }.joined(separator: "&")
guard
let encodedMailtoQuery = mailtoQuery.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let mailUrl = URL(string: "mailto:\(emailRecipients.joined(separator: ","))?\(encodedMailtoQuery)"),
UIApplication.shared.canOpenURL(mailUrl)
else {
let alertView = UIAlertController(title: nil, message: "menu.help.unableToSendEmail.text".localized(), preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "general.ok".localized(), style: .default, handler: nil))
self.viewControllerForPresentation().present(alertView, animated: true, completion: nil)
return
}
UIApplication.shared.open(mailUrl)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment