Skip to content

Commit

Permalink
Support sending mail from the default mail app
Browse files Browse the repository at this point in the history
  • Loading branch information
Arclite committed Jul 6, 2024
1 parent c8229ff commit e6bd7c3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
4 changes: 4 additions & 0 deletions App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<false/>
<key>LSApplicationCategoryType</key>
<string>public.app-category.photography</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
61 changes: 61 additions & 0 deletions Modules/Capabilities/SettingsUI/Sources/List/Mail/MailButton.swift
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
}
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) {}
}

0 comments on commit e6bd7c3

Please sign in to comment.