Hi, I am using UIViewControllerRepresentable to send email from SwiftUI. The mail goes out, but I do not get the swoosh sound. I think that is necessary to assure the user that the mail was sent. If I can not get the swosh sound, is there something I can check to put up some indication that the mail was sent?
I am using this code:
struct MailView: UIViewControllerRepresentable {
@EnvironmentObject var theBody: GlobalData
var imageData: NoteImageData
@Binding var isShowing: Bool
@Binding var result: Result<MFMailComposeResult, Error>?
class Coordinator: NSObject, MFMailComposeViewControllerDelegate {
@Binding var isShowing: Bool
@Binding var result: Result<MFMailComposeResult, Error>?
init(isShowing: Binding<Bool>,
result: Binding<Result<MFMailComposeResult, Error>?>) {
isShowing = isShowing
result = result
}
func mailComposeController( controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult,
error: Error?) {
defer {
isShowing = false
}
guard error == nil else {
self.result = .failure(error!)
return
}
self.result = .success(result)
}
}
func makeCoordinator() -> Coordinator {
return Coordinator(isShowing: $isShowing,
result: $result)
}
func makeUIViewController(context: UIViewControllerRepresentableContext<MailView>) -> MFMailComposeViewController {
let vc = MFMailComposeViewController()
vc.mailComposeDelegate = context.coordinator
vc.setSubject("")
//vc.setMessageBody(imageData.description , isHTML: true)
vc.setMessageBody( theBody.mailBody, isHTML: true)
return vc
}
func updateUIViewController( uiViewController: MFMailComposeViewController,
context: UIViewControllerRepresentableContext<MailView>) {
}
}
I am using this code:
struct MailView: UIViewControllerRepresentable {
@EnvironmentObject var theBody: GlobalData
var imageData: NoteImageData
@Binding var isShowing: Bool
@Binding var result: Result<MFMailComposeResult, Error>?
class Coordinator: NSObject, MFMailComposeViewControllerDelegate {
@Binding var isShowing: Bool
@Binding var result: Result<MFMailComposeResult, Error>?
init(isShowing: Binding<Bool>,
result: Binding<Result<MFMailComposeResult, Error>?>) {
isShowing = isShowing
result = result
}
func mailComposeController( controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult,
error: Error?) {
defer {
isShowing = false
}
guard error == nil else {
self.result = .failure(error!)
return
}
self.result = .success(result)
}
}
func makeCoordinator() -> Coordinator {
return Coordinator(isShowing: $isShowing,
result: $result)
}
func makeUIViewController(context: UIViewControllerRepresentableContext<MailView>) -> MFMailComposeViewController {
let vc = MFMailComposeViewController()
vc.mailComposeDelegate = context.coordinator
vc.setSubject("")
//vc.setMessageBody(imageData.description , isHTML: true)
vc.setMessageBody( theBody.mailBody, isHTML: true)
return vc
}
func updateUIViewController( uiViewController: MFMailComposeViewController,
context: UIViewControllerRepresentableContext<MailView>) {
}
}