如何从Swift打开邮件应用 [英] How to open mail app from Swift
本文介绍了如何从Swift打开邮件应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个简单的快捷应用程序,用户在其中输入电子邮件地址,然后按一个按钮打开邮件应用程序,并将输入的地址显示在地址栏中.我知道如何在Objective-C中做到这一点,但是我很难让它在Swift中工作.
Im working on a simple swift app where the user inputs an email address and presses a button which opens the mail app, with the entered address in the address bar. I know how to do this in Objective-C, but I'm having trouble getting it to work in Swift.
推荐答案
您可以在iOS中使用简单的mailto:链接打开邮件应用.
You can use simple mailto: links in iOS to open the mail app.
let email = "foo@bar.com"
if let url = URL(string: "mailto:\(email)") {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
这篇关于如何从Swift打开邮件应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文