import MessageUI
import SwiftUI
import UIKit
struct MailView: UIViewControllerRepresentable {
@Environment(\.presentationMode) var presentation
@Binding var result: Result<MFMailComposeResult, Error>?
class Coordinator: NSObject, MFMailComposeViewControllerDelegate {
@Binding var presentation: PresentationMode
@Binding var result: Result<MFMailComposeResult, Error>?
init(presentation: Binding<PresentationMode>,
result: Binding<Result<MFMailComposeResult, Error>?>)
{
_presentation = presentation
_result = result
}
func mailComposeController(_: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult,
error: Error?)
{
defer {
$presentation.wrappedValue.dismiss()
}
guard error == nil else {
self.result = .failure(error!)
return
}
self.result = .success(result)
}
}
func makeCoordinator() -> Coordinator {
return Coordinator(presentation: presentation,
result: $result)
}
func makeUIViewController(context: UIViewControllerRepresentableContext<MailView>) -> MFMailComposeViewController {
let vc = MFMailComposeViewController()
vc.setToRecipients(["[email protected]"])
vc.setSubject("ํ๋๋
์ฌ๋ ๊ด๋ จ ๋ฌธ์")
vc.setMessageBody("""
๋ฌธ์ ๋ด์ฉ์ ์ฌ๊ธฐ์ ์
๋ ฅํด์ฃผ์ธ์.
--------------------
ํ๋๋
์ฌ๋ ๋ฒ์ : ((Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)!)
iOS ๋ฒ์ : (UIDevice.current.systemVersion)
๊ธฐ๊ธฐ: (UIDevice.current.model)
""", isHTML: false)
vc.mailComposeDelegate = context.coordinator
return vc
}
func updateUIViewController(_: MFMailComposeViewController,
context _: UIViewControllerRepresentableContext<MailView>) {}
}