【问题标题】:how to pass in subject and body text in swiftui mail app?如何在swiftui邮件应用程序中传递主题和正文?
【发布时间】:2020-09-07 18:24:09
【问题描述】:

我试图在打开邮件应用程序时传递主题和正文,但由于某种原因,当我传递参数时邮件不会发生。谁能在我的代码中看到我做错了什么?或者如果人们有另一种方法让我在 swiftui 中工作,那将是很棒的。感谢您的帮助。

这是我的代码:

Button(action: {
                         
     let email = "test@gmail.com"
     let subject = "Feedback"
    let body = "Please provide your feedback here, and we will contact you within the next 24-48 hours."
   guard let url = URL(string: "mailto:\(email)?subject=\(subject)&body=\(body)") else { return }

   UIApplication.shared.open(url)
}) {

  Text("Contact Us - ")
 }

【问题讨论】:

    标签: ios swift swiftui uiapplication


    【解决方案1】:

    一般情况下,您需要为组合 URL 的组件添加百分比转义,例如

    let email = "test@gmail.com"
    let subject = "Feedback"
    let body = "Please provide your feedback here, and we will contact you within the next 24-48 hours."
    guard let url = URL(string: "mailto:\(email)?subject=\(subject.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "")&body=\(body.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "")") else { return }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      相关资源
      最近更新 更多