【问题标题】:New line in emailBody not working in swiftemailBody 中的新行无法快速工作
【发布时间】:2023-03-09 08:47:02
【问题描述】:

我有这段代码用于在 emailMessageBody 中显示一些内容。代码如下。

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)

你们看到我在内容中添加了“\n”,但它没有在 emailBody 中显示新行。 如果有人知道如何在 emailMessageBody 中获取一些新行,请帮助。

【问题讨论】:

  • 使用 ,因为电子邮件正文是 HTML 格式,而在 html 中,您必须使用
    来换行。
  • @Kampai 天哪。我怎么能忘记那个。//
  • 你需要添加标签<br>这个。不是\br

标签: ios xcode swift mfmailcomposeviewcontroller


【解决方案1】:

您需要使用</br> 而不是\n

所以您的示例代码将如下所示

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)

【讨论】:

  • 这个答案出现在低质量审查队列中,大概是因为您没有提供任何代码解释。如果此代码回答了问题,请考虑在答案中添加一些解释代码的文本。这样一来,您就更有可能获得更多支持,并帮助提问者学习新知识。
【解决方案2】:

如果要使用\n,则必须在setMessageBody调用中将参数isHTML设置为false,否则在设置内容时必须使用&lt;/br&gt;而不是\n消息正文。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多