Sco*_*ank 2 uiapplication ios swift 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 - ")
}
Run Code Online (Sandbox Code Playgroud)
一般来说,您需要为组合 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 }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1408 次 |
| 最近记录: |