我的应用程序中有一个联系我们页面,其中显示了我的Facebook,Twitter和网站页面。我已经设法通过将IBAction链接到按钮来使它们正常工作。我在下面使用的代码,但我想对我的电子邮件做同样的事情。当按下按钮时,我想打开手机上的电子邮件,并且“To”“subject”字段已经填写。我不想在我的应用程序中添加电子邮件表单,因为这是我唯一的事情可以找到信息。 有没有办法实现这个目标?
import UIKit
import MessageUI
class SocialViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func openWeb(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string: "http://www.xxxxxxxxxxxx.com")!)
}
@IBAction func openFB(sender: AnyObject) {
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb://profile/XXXXXXXX")!) {
UIApplication.sharedApplication().openURL(NSURL(string: "fb://profile/XXXXXXXXXX")!)
} else {
UIApplication.sharedApplication().openURL(NSURL(string: "https://facebook.com/XXXXXXXXX")!)
}
}
@IBAction func openTW(sender: AnyObject) {
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "tw://profile/XXXXXXXXX")!) {
UIApplication.sharedApplication().openURL(NSURL(string: "fb://profile/XXXXXXX")!)
} else {
UIApplication.sharedApplication().openURL(NSURL(string: "https://twitter.com/XXXXXXX")!)
}
}
}
答案 0 :(得分:1)
通过本地邮件应用程序发送Swift
的邮件,将MFMailComposeViewControllerDelegate
添加到您的类继承中
在您的操作中添加以下内容:
var mail: MFMailComposeViewController!
let toRecipients = ["test@mail.com"]
let subject = "Subject"
let body = "Your body text"
mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(toRecipients)
mail.setSubject(subject)
mail.setMessageBody(body, isHTML: true)
presentViewController(mail, animated: true, completion: nil)