I'm having 2 issues with the below code Im hoping you can help with. EmailHelper() is my class.
- The lines are not breaking correctly and everything for the body is just one ongoing sentence.
- I can't get Application Name, App Version, App Build, or Device Model to display correctly. Obviously I don't have anything listed for any of those other than Device model, because I can't figure out how to pull it.
HStack {
var bodyString = """
Application:
iOS Version: \(UIDevice.current.systemVersion)
Device Model: \(UIDevice.current.model)
App Version:
App Build:
WHAT ISSUE ARE YOU EXPERIENCING? (state in detail below)
"""
Button(action: {
EmailHelper.shared.sendEmail(subject: "Bug Report", body: bodyString,
to: "blah@blah.com") { (isWorked) in
if !isWorked{
print("Mail Send Fail")
}
}
}, label: {
Text(" Report Bug")
})
}
EMAILHELPER
import Foundation
import MessageUI
class EmailHelper: NSObject, MFMailComposeViewControllerDelegate {
public static let shared = EmailHelper()
func sendEmail(subject:String, body:String, to:String, completion: @escaping (Bool) -> Void){
if MFMailComposeViewController.canSendMail(){
let mail = MFMailComposeViewController()
mail.setSubject(subject)
mail.setMessageBody(body, isHTML: true)
mail.setToRecipients([to])
mail.mailComposeDelegate = self
UIApplication.shared.windows.first?.rootViewController?.present(mail, animated: true, completion: nil)
}
completion(MFMailComposeViewController.canSendMail())
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
}