如何解决如何在swiftui邮件应用程序中传递主题和正文文本?
我试图在打开邮件应用程序时传递主题和正文文本,但是由于某些原因,当我传递参数时邮件不会发生。谁能在我的代码中看到我做错了什么?或者,如果有其他方法让我在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 - ")
}
解决方法
通常,您需要为组成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 }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。