0

I'm having 2 issues with the below code Im hoping you can help with. EmailHelper() is my class.

  1. The lines are not breaking correctly and everything for the body is just one ongoing sentence.
  2. 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)
     }
}
  • `mail.setMessageBody(body, isHTML: true)` Your content isn't HTML... Why is this tagged with `CoreData`? Search for the missing values: https://stackoverflow.com/questions/25965239/how-do-i-get-the-app-version-and-build-number-using-swift etc. – Larme Oct 18 '22 at 18:00

0 Answers0