From 41ed10e76e33107a4d305809a8f401fbf4af5cb8 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 5 Jul 2019 11:10:04 +0200 Subject: [PATCH] Fall back to mailto URL when no email account Useful with third party mail apps. --- CHANGELOG.md | 3 ++- Passepartout-iOS/Global/IssueReporter.swift | 13 ++++++++--- .../Organizer/OrganizerViewController.swift | 22 ++++++++++++++----- Submodules/Core | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cda2169e..46a1a98f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 1.8.0 Beta 1963 (2019-07-05) +## Unreleased ### Added @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Support third party apps when sending e-mails. - Refreshed infrastructures are not retained. [core#1](https://github.com/passepartoutvpn/passepartout-core-apple/issues/1) - Portuguese bound to Brazil region. - German spelling of "Default gateway". diff --git a/Passepartout-iOS/Global/IssueReporter.swift b/Passepartout-iOS/Global/IssueReporter.swift index ab34f4a0..61adec9a 100644 --- a/Passepartout-iOS/Global/IssueReporter.swift +++ b/Passepartout-iOS/Global/IssueReporter.swift @@ -57,9 +57,16 @@ class IssueReporter: NSObject { func present(in viewController: UIViewController, withAttachments attachments: Attachments) { guard MFMailComposeViewController.canSendMail() else { - let alert = Macros.alert(L10n.Core.IssueReporter.title, L10n.Core.Global.emailNotConfigured) - alert.addCancelAction(L10n.Core.Global.ok) - viewController.present(alert, animated: true, completion: nil) + let app = UIApplication.shared + let V = AppConstants.IssueReporter.Email.self + let body = V.body(V.template, DebugLog(raw: "--").decoratedString()) + guard let url = Utils.mailto(to: V.recipient, subject: V.subject, body: body), app.canOpenURL(url) else { + let alert = Macros.alert(L10n.Core.IssueReporter.title, L10n.Core.Global.emailNotConfigured) + alert.addCancelAction(L10n.Core.Global.ok) + viewController.present(alert, animated: true, completion: nil) + return + } + app.open(url, options: [:], completionHandler: nil) return } diff --git a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift index 97020af1..188a3fc0 100644 --- a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift @@ -223,17 +223,27 @@ class OrganizerViewController: UITableViewController, TableModelHost { } private func offerTranslation() { + let V = AppConstants.Translations.Email.self + let recipient = V.recipient + let subject = V.subject + let body = V.body(V.template) + guard MFMailComposeViewController.canSendMail() else { - let alert = Macros.alert(L10n.Core.IssueReporter.title, L10n.Core.Global.emailNotConfigured) - alert.addCancelAction(L10n.Core.Global.ok) - present(alert, animated: true, completion: nil) + let app = UIApplication.shared + guard let url = Utils.mailto(to: recipient, subject: subject, body: body), app.canOpenURL(url) else { + let alert = Macros.alert(L10n.Core.Translations.title, L10n.Core.Global.emailNotConfigured) + alert.addCancelAction(L10n.Core.Global.ok) + present(alert, animated: true, completion: nil) + return + } + app.open(url, options: [:], completionHandler: nil) return } let vc = MFMailComposeViewController() - vc.setToRecipients([AppConstants.Translations.Email.recipient]) - vc.setSubject(AppConstants.Translations.Email.subject) - vc.setMessageBody(AppConstants.Translations.Email.body(AppConstants.Translations.Email.template), isHTML: false) + vc.setToRecipients([recipient]) + vc.setSubject(subject) + vc.setMessageBody(body, isHTML: false) vc.mailComposeDelegate = self vc.apply(Theme.current) present(vc, animated: true, completion: nil) diff --git a/Submodules/Core b/Submodules/Core index 6dd5a4e9..d2701072 160000 --- a/Submodules/Core +++ b/Submodules/Core @@ -1 +1 @@ -Subproject commit 6dd5a4e997f768bf626612dddb7fa321f4899fde +Subproject commit d27010723474d4f0c7fe0199d847b155b5b193c7