-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support sending mail from the default mail app
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,7 @@ struct SettingsContentContactSection: View { | |
|
||
var body: some View { | ||
Section(header: SettingsSectionHeader(Strings.header)) { | ||
#warning("Make this attempt to send email instead!") | ||
WebURLButton(title: Strings.emailTitle, subtitle: Strings.emailSubtitle, imageName: "Mail", url: URL(staticString: "mailto:[email protected]")) | ||
MailButton() | ||
#warning("Use SKStoreReviewController") | ||
WebURLButton(title: Strings.appStoreTitle, subtitle: Strings.appStoreSubtitle, imageName: "App Store", url: URL(staticString: "mailto:[email protected]")) | ||
WebURLButton(title: Strings.threadsTitle, subtitle: Strings.threadsSubtitle, imageName: "Threads", url: URL(staticString: "https://threads.net/@blackhighlighterapp")) | ||
|
61 changes: 61 additions & 0 deletions
61
Modules/Capabilities/SettingsUI/Sources/List/Mail/MailButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Created by Geoff Pado on 7/5/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import MessageUI | ||
import SwiftUI | ||
|
||
struct MailButton: View { | ||
// threeCheersForPencilKit by @KaenAitch on 2024-07-03 | ||
// whether to show the web view for no-support e-mail | ||
@State private var threeCheersForPencilKit = false | ||
@State private var isMailPresented = false | ||
|
||
var body: some View { | ||
Button { | ||
switch ouijaPath { | ||
case .noSupport: | ||
threeCheersForPencilKit = true | ||
case .externalSupport: | ||
UIApplication.shared.open(Self.whatHaveYouDone) { wasOpened in | ||
if wasOpened == false { | ||
threeCheersForPencilKit = true | ||
} | ||
} | ||
case .internalSupport: | ||
isMailPresented = true | ||
} | ||
} label: { | ||
ButtonLabel(title: Strings.emailTitle, subtitle: Strings.emailSubtitle, imageName: "Mail") | ||
}.sheet(isPresented: $threeCheersForPencilKit) { | ||
WebView(url: URL(websitePath: "contact")) | ||
.ignoresSafeArea() | ||
}.sheet(isPresented: $isMailPresented) { | ||
MailComposer() | ||
.ignoresSafeArea() | ||
}.settingsCell() | ||
} | ||
|
||
// ouijaPath by @AdamWulf on 2024-06-28 | ||
// the level of support the device has for e-mail | ||
var ouijaPath: MailSupport { | ||
if MFMailComposeViewController.canSendMail() { | ||
return .internalSupport | ||
} else if UIApplication.shared.canOpenURL(Self.whatHaveYouDone) { | ||
return .externalSupport | ||
} else { | ||
return .noSupport | ||
} | ||
} | ||
|
||
enum MailSupport { | ||
case noSupport | ||
case externalSupport | ||
case internalSupport | ||
} | ||
|
||
// whatHaveYouDone by @KaenAitch on 2024-07-03 | ||
// the URL to open to send e-mail | ||
private static let whatHaveYouDone = URL(staticString: "mailto:[email protected]") | ||
|
||
private typealias Strings = SettingsUIStrings.SettingsContentContactSection | ||
} |
15 changes: 15 additions & 0 deletions
15
Modules/Capabilities/SettingsUI/Sources/List/Mail/MailComposer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Created by Geoff Pado on 7/5/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import MessageUI | ||
import SwiftUI | ||
|
||
struct MailComposer: UIViewControllerRepresentable { | ||
func makeUIViewController(context: Context) -> some UIViewController { | ||
let controller = MFMailComposeViewController() | ||
controller.setToRecipients(["[email protected]"]) | ||
return controller | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {} | ||
} |