Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line in emailBody not working in swift

I have this code for showing some content in emailMessageBody. The code is given below.

var emailViewController : MFMailComposeViewController = MFMailComposeViewController()
        emailViewController.mailComposeDelegate = self
        emailViewController.setToRecipients(["----"])
        emailViewController.setSubject("----")
        emailViewController.setMessageBody("\n\n\n" + "-- \r\n " + "----- Device : \(self.deviceName), App Version : \(self.appVersion), Model : \(deviceModel) , iOS Version : \(self.deviceVersion), Country Code : \(self.countryCode), Localised Model : \(deviceLocalizedModel) \n \n \n", isHTML: true)
        self.presentViewController(emailViewController, animated: true, completion: nil)

You guys see that i put "\n" in the content, but its not showing new lines in the emailBody. If anyone know how to get some new lines in emailMessageBody, Please help.

like image 250
Alvin Varghese Avatar asked Nov 17 '14 13:11

Alvin Varghese


2 Answers

You need to use </br> instead of \n

So your example code will look like the following

var emailViewController : MFMailComposeViewController = MFMailComposeViewController()
    emailViewController.mailComposeDelegate = self
    emailViewController.setToRecipients(["----"])
    emailViewController.setSubject("----")
    emailViewController.setMessageBody("</br></br></br>" + "-- </br> " + "----- Device : \(self.deviceName), App Version : \(self.appVersion), Model : \(deviceModel) , iOS Version : \(self.deviceVersion), Country Code : \(self.countryCode), Localised Model : \(deviceLocalizedModel) </br></br></br>", isHTML: true)
    self.presentViewController(emailViewController, animated: true, completion: nil)
like image 82
Mohamed Saleh Avatar answered Sep 26 '22 17:09

Mohamed Saleh


If you want to use \n you have to set the parameter isHTML to false in the setMessageBody call, otherwise you must use </br> instead of \n when you set the content for the message body.

like image 24
Miguel Gomes Avatar answered Sep 23 '22 17:09

Miguel Gomes