Merge pull request #2717 from stuartbreckenridge/2711
Changes to mailto handling
This commit is contained in:
commit
a88afc77d5
@ -315,15 +315,12 @@ extension WebViewController: WKNavigationDelegate {
|
||||
} else if components?.scheme == "mailto" {
|
||||
decisionHandler(.cancel)
|
||||
|
||||
guard let emailAddress = url.emailAddress else {
|
||||
guard let emailAddress = url.percentEncodedEmailAddress else {
|
||||
return
|
||||
}
|
||||
|
||||
if MFMailComposeViewController.canSendMail() {
|
||||
let mailComposeViewController = MFMailComposeViewController()
|
||||
mailComposeViewController.setToRecipients([emailAddress])
|
||||
mailComposeViewController.mailComposeDelegate = self
|
||||
self.present(mailComposeViewController, animated: true, completion: {})
|
||||
if UIApplication.shared.canOpenURL(emailAddress) {
|
||||
UIApplication.shared.open(emailAddress, options: [.universalLinksOnly : false], completionHandler: nil)
|
||||
} else {
|
||||
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))
|
||||
@ -418,15 +415,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
|
||||
|
||||
private struct ImageClickMessage: Codable {
|
||||
|
@ -81,5 +81,9 @@
|
||||
<string>group.$(ORGANIZATION_IDENTIFIER).NetNewsWire.iOS</string>
|
||||
<key>AppIdentifierPrefix</key>
|
||||
<string>$(AppIdentifierPrefix)</string>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>mailto</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@ -15,6 +15,11 @@ extension URL {
|
||||
scheme == "mailto" ? URLComponents(url: self, resolvingAgainstBaseURL: false)?.path : nil
|
||||
}
|
||||
|
||||
/// Percent encoded `mailto` URL for use with `canOpenUrl`. If the URL doesn't contain the `mailto` scheme, this is `nil`.
|
||||
var percentEncodedEmailAddress: URL? {
|
||||
scheme == "mailto" ? self.string.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)?.url : nil
|
||||
}
|
||||
|
||||
/// URL pointing to current app version release notes.
|
||||
static var releaseNotes: URL {
|
||||
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? ""
|
||||
|
@ -356,16 +356,12 @@ extension WebViewController: WKNavigationDelegate {
|
||||
} else if components?.scheme == "mailto" {
|
||||
decisionHandler(.cancel)
|
||||
|
||||
guard let emailAddress = url.emailAddress else {
|
||||
guard let emailAddress = url.percentEncodedEmailAddress else {
|
||||
return
|
||||
}
|
||||
|
||||
if MFMailComposeViewController.canSendMail() {
|
||||
let mailComposeViewController = MFMailComposeViewController()
|
||||
mailComposeViewController.setToRecipients([emailAddress])
|
||||
mailComposeViewController.setSubject(url.valueFor("subject") ?? "")
|
||||
mailComposeViewController.mailComposeDelegate = self
|
||||
self.present(mailComposeViewController, animated: true, completion: {})
|
||||
if UIApplication.shared.canOpenURL(emailAddress) {
|
||||
UIApplication.shared.open(emailAddress, options: [.universalLinksOnly : false], completionHandler: nil)
|
||||
} else {
|
||||
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))
|
||||
@ -459,14 +455,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
|
||||
|
||||
|
@ -54,6 +54,10 @@
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>mailto</string>
|
||||
</array>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
|
Loading…
x
Reference in New Issue
Block a user