如果你想開,而不是顯示MFMailComposeViewController
由他人已經提到了內置電子郵件應用程序,你可以構建一個mailto:
鏈接是這樣的:
let subject = "My subject"
let body = "The awesome body of my email."
let encodedParams = "subject=\(subject)&body=\(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
let url = "mailto:[email protected]?\(encodedParams)"
if let emailURL = NSURL(url) {
if UIApplication.sharedApplication().canOpenURL(emailURL) {
UIApplication.sharedApplication().openURL(emailURL)
}
}
剛拯救任何人打字,2016年的語法已略有改變:
let subject = "Some subject"
let body = "Plenty of email body."
let coded = "mailto:[email protected]?subject=\(subject)&body=\(body)".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet())
if let emailURL:NSURL = NSURL(string: coded!)
{
if UIApplication.sharedApplication().canOpenURL(emailURL)
{
UIApplication.sharedApplication().openURL(emailURL)
}
請在'郵寄地址一些研究:'URL方案。您可以提供「收件人」地址,「抄送」地址,主題和郵件正文。但當然最好的選擇是做下面的答案。 – rmaddy