我如何在swift 5中的text()中使用邮件链接,swiftui
Swift 5中有数十个邮政链接的堆栈volfflow答案。
共识看起来像这样,
let url = NSURL(string: "mailto:[email protected]")
UIApplication.sharedApplication().openURL(url)
但是我如何实际使用此代码?理想情况下在警报中,但至少是一般文本元素
import SwiftUI
struct MainMenu: View {
@State private var showAlert = false
// What do I put here
var emailLink:UIApplication {
let url = URL(string: "mailto:[email protected]")!
return UIApplication.shared.openURL(url)
}
// To make it work in here
var body: some View {
HStack(alignment: .center, spacing: .zero, content: {
Text(
"Here is an email link \(emailLink)"
)
Button(action: {
showAlert = true
}) {
Text("MENU")
}
.alert(isPresented: $showAlert, content: {
Alert(
title: Text("Title Here"),
message: Text(
"Need Help, \(emailLink)"
)
)
})
})
}
}
There are dozens of Stackoverflow answers for mailto links in Swift 5.
The consensus look like this
let url = NSURL(string: "mailto:[email protected]")
UIApplication.sharedApplication().openURL(url)
But how do I actually use this code? Ideally in an alert, but at least a general Text element
import SwiftUI
struct MainMenu: View {
@State private var showAlert = false
// What do I put here
var emailLink:UIApplication {
let url = URL(string: "mailto:[email protected]")!
return UIApplication.shared.openURL(url)
}
// To make it work in here
var body: some View {
HStack(alignment: .center, spacing: .zero, content: {
Text(
"Here is an email link \(emailLink)"
)
Button(action: {
showAlert = true
}) {
Text("MENU")
}
.alert(isPresented: $showAlert, content: {
Alert(
title: Text("Title Here"),
message: Text(
"Need Help, \(emailLink)"
)
)
})
})
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有警报,基于
Without an Alert, based on the suggestive comment of George this works:
您可以使用
环境
varopenUrl
为此,documentation 在这里。You can use
Environment
varopenURL
for this, documentation here.