我有一个通过UIButton触发的UIAlertView。通过UIAlertView按钮打开iOS电子邮件应用程序
UIAlertView显示两个按钮,“打开电子邮件”和“取消”。
“取消”从视图中删除UIAlert。我试图这样做,当用户点击“打开电子邮件”时,他们的设备将打开默认的电子邮件应用程序的撰写屏幕,其中的电子邮件地址已在“发件人”部分。
使用斯威夫特3.
谢谢!
import UIKit
import Kingfisher
class SettingsViewController: UIViewController {
@IBAction func copyrightInfo(_ sender: Any) {
let alert = UIAlertController(title: "Copyright Info", message: "text", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "I understand", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
@IBAction func helpfeedbackAlert(_ sender: Any) {
let alertController = UIAlertController(title: "Help & Feedback", message: "text", preferredStyle: .alert)
let cancel = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
let openEmail = UIAlertAction(title: "Open Email", style: .default, handler: nil)
alertController.addAction(openEmail)
alertController.addAction(cancel)
self.present(alertController, animated: true, completion: nil)
}
@IBAction func clearCache(_ sender: Any) {
// SDImageCache.shared().clearMemory()
// SDImageCache.shared().clearDisk()
// Clear memory cache right away.
ImageCache.default.clearMemoryCache()
// Clear disk cache. This is an async operation.
ImageCache.default.clearDiskCache()
}
@IBAction func rateApp(_ sender: Any) {
if let url = URL(string: "https://www.google.com") {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:]) {
boolean in
// do something with the boolean
}
} else {
// Fallback on earlier versions
}
}
}
@IBAction func purchasePhotos(_ sender: Any) {
if let url = URL(string: "https://google.com") {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:]) {
boolean in
// do something with the boolean
}
} else {
// Fallback on earlier versions
}
}
}
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.
}
override var prefersStatusBarHidden: Bool {
get {
return true
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
非常感谢!对于如何将MFMailCompose代码添加到UIAlertAction中的处理程序有点困惑。它在连接到UIButton时效果很好,但在UIAlertAction中放入处理程序时似乎不起作用。 – Miles
在按钮操作中做什么,但在关闭中(同样的“在此处发送您的电子邮件......”存在的块)的操作完全相同。 –
现在工作!谢谢。我不得不加上“自我”。在“present(mail,animated:true)”行上,当电子邮件屏幕打开并且我点击“取消”或发送电子邮件时,邮件视图不会消失。 – Miles