Acquiesce to the user’s request for a different default mail app.
This commit is contained in:
Stuart Breckenridge 2021-01-08 12:15:16 +08:00
parent 9e7f2460e4
commit c59e3e4ddf
No known key found for this signature in database
GPG Key ID: ED2F112EEA9EF8A5
4 changed files with 19 additions and 30 deletions

View File

@ -315,15 +315,14 @@ extension WebViewController: WKNavigationDelegate {
} else if components?.scheme == "mailto" { } else if components?.scheme == "mailto" {
decisionHandler(.cancel) decisionHandler(.cancel)
guard let emailAddress = url.emailAddress else { guard let _ = url.emailAddress else {
return return
} }
if MFMailComposeViewController.canSendMail() { if UIApplication.shared.canOpenURL(url) {
let mailComposeViewController = MFMailComposeViewController() UIApplication.shared.open(url, options: [.universalLinksOnly : false]) { (success) in
mailComposeViewController.setToRecipients([emailAddress]) print(success)
mailComposeViewController.mailComposeDelegate = self }
self.present(mailComposeViewController, animated: true, completion: {})
} else { } else {
let alert = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: NSLocalizedString("This device cannot send emails.", comment: "This device cannot send emails."), preferredStyle: .alert) let alert = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: NSLocalizedString("This device cannot send emails.", comment: "This device cannot send emails."), preferredStyle: .alert)
alert.addAction(.init(title: NSLocalizedString("Dismiss", comment: "Dismiss"), style: .cancel, handler: nil)) alert.addAction(.init(title: NSLocalizedString("Dismiss", comment: "Dismiss"), style: .cancel, handler: nil))
@ -418,15 +417,6 @@ extension WebViewController: UIScrollViewDelegate {
} }
// MARK: MFMailComposeViewControllerDelegate
extension WebViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
self.dismiss(animated: true, completion: nil)
}
}
// MARK: JSON // MARK: JSON
private struct ImageClickMessage: Codable { private struct ImageClickMessage: Codable {

View File

@ -81,5 +81,9 @@
<string>group.$(ORGANIZATION_IDENTIFIER).NetNewsWire.iOS</string> <string>group.$(ORGANIZATION_IDENTIFIER).NetNewsWire.iOS</string>
<key>AppIdentifierPrefix</key> <key>AppIdentifierPrefix</key>
<string>$(AppIdentifierPrefix)</string> <string>$(AppIdentifierPrefix)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
</dict> </dict>
</plist> </plist>

View File

@ -356,16 +356,14 @@ extension WebViewController: WKNavigationDelegate {
} else if components?.scheme == "mailto" { } else if components?.scheme == "mailto" {
decisionHandler(.cancel) decisionHandler(.cancel)
guard let emailAddress = url.emailAddress else { guard let _ = url.emailAddress else {
return return
} }
if MFMailComposeViewController.canSendMail() { if UIApplication.shared.canOpenURL(url) {
let mailComposeViewController = MFMailComposeViewController() UIApplication.shared.open(url, options: [.universalLinksOnly : false]) { (success) in
mailComposeViewController.setToRecipients([emailAddress]) print(success)
mailComposeViewController.setSubject(url.valueFor("subject") ?? "") }
mailComposeViewController.mailComposeDelegate = self
self.present(mailComposeViewController, animated: true, completion: {})
} else { } else {
let alert = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: NSLocalizedString("This device cannot send emails.", comment: "This device cannot send emails."), preferredStyle: .alert) let alert = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: NSLocalizedString("This device cannot send emails.", comment: "This device cannot send emails."), preferredStyle: .alert)
alert.addAction(.init(title: NSLocalizedString("Dismiss", comment: "Dismiss"), style: .cancel, handler: nil)) alert.addAction(.init(title: NSLocalizedString("Dismiss", comment: "Dismiss"), style: .cancel, handler: nil))
@ -459,14 +457,7 @@ extension WebViewController: UIScrollViewDelegate {
} }
// MARK: MFMailComposeViewControllerDelegate
extension WebViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
self.dismiss(animated: true, completion: nil)
}
}
// MARK: JSON // MARK: JSON

View File

@ -54,6 +54,10 @@
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string> <string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>