-1
我已經更新了Swift到2.0,並自動轉換了代碼,但我看到了一些我仍然想修復的錯誤。更新到Swift 2.0時的代碼問題。 「無法轉換價值..」
其中之一就是:「不能轉換類型,期望的參數類型「[字符串]的‘[AnyObject]’值
該VC創建發起一封郵件屏幕,以幫助用戶聯繫到? 。我
錯誤是在FUNC lanzarEmail以下行:
mailController .setToRecipients(收件人)
代碼:
import UIKit
import MessageUI
class tuPropiaHistoriaVC: UIViewController,MFMailComposeViewControllerDelegate {
var alert: UIAlertView?
var subjectText:String?
var destinatario:AnyObject!
var mailController:MFMailComposeViewController?
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
//Recipients
subjectText = "Mi historia de éxito/superación."
destinatario = "[email protected]"
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func lanzarEmail(sender: AnyObject) {
if(MFMailComposeViewController.canSendMail()){
//AlertView
alert = UIAlertView()
alert!.addButtonWithTitle("Ok")
mailController = MFMailComposeViewController()
//asignar delegado al controlador de email
mailController?.mailComposeDelegate = self
//Completar objeto mailController
mailController?.setSubject(subjectText!)
var recipients = [destinatario]
mailController?.setToRecipients(recipients)
self.presentViewController(mailController!, animated: true, completion: nil)
}else
{
let sendMailErrorAlert = UIAlertView(title: "No se puede enviar Email", message: "Por favor configura tu app Mail para poder enviar correos", delegate: self, cancelButtonTitle: "Entendido")
sendMailErrorAlert.show()
self.dismissViewControllerAnimated(false, completion: nil)
}
}
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
switch result.rawValue {
case MFMailComposeResultCancelled.rawValue:
//se cancelo envio
alert!.title = "Envio cancelado"
alert!.message = "Se canceló el envio"
alert!.show()
case MFMailComposeResultSaved.rawValue:
//se guardo draft
alert!.title = "Correo guardado"
alert!.message = "Se guardó el correo en la app de Mail"
alert!.show()
case MFMailComposeResultFailed.rawValue:
//fallo el envio
alert!.title = "Error"
alert!.message = "El correo no pudo ser enviado"
alert!.show()
case MFMailComposeResultSent.rawValue:
//el mail se pudo enviar y esta en la pila de envio
alert!.title = "Correo enviado"
alert!.message = "El correo se envió exitosamente"
alert!.show()
default:
break
}
mailController?.dismissViewControllerAnimated(true,
//Clousure a ejecutar al finalizar de mostrar la vista
completion: {() -> Void in
//Cerrar pantalla del view base, requiere que la conexion entre pantallas sea del tipo seague
self.dismissViewControllerAnimated(true, completion: nil)
})
}
}
你是好人!謝謝 – FactorJose