मैं इन-ऐप ईमेल को लागू करने के लिए तेज़ी से उपयोग करना चाहता हूं। जब मैं बटन पर क्लिक करता हूं, तो ईमेल विंडो पॉप अप होती है। हालांकि, मैं अपना ईमेल भेजने में असमर्थ हूं। इसके अलावा, जब मैं रद्द-ड्राफ्ट ड्राफ्ट पर क्लिक करता हूं, तो मैं मूल स्क्रीन पर वापस नहीं जा सकता।इन-ऐप ईमेल को लागू करने के लिए स्विफ्ट का उपयोग करने में विफल
import UIkit
import MessageUI
class Information : UIViewController, MFMailComposeViewControllerDelegate{
var myMail: MFMailComposeViewController!
@IBAction func sendReport(sender : AnyObject) {
if(MFMailComposeViewController.canSendMail()){
myMail = MFMailComposeViewController()
//myMail.mailComposeDelegate
// set the subject
myMail.setSubject("My report")
//To recipients
var toRecipients = ["[email protected]"]
myMail.setToRecipients(toRecipients)
//CC recipients
var ccRecipients = ["[email protected]"]
myMail.setCcRecipients(ccRecipients)
//CC recipients
var bccRecipients = ["[email protected]"]
myMail.setBccRecipients(ccRecipients)
//Add some text to the message body
var sentfrom = "Email sent from my app"
myMail.setMessageBody(sentfrom, isHTML: true)
//Include an attachment
var image = UIImage(named: "Gimme.png")
var imageData = UIImageJPEGRepresentation(image, 1.0)
myMail.addAttachmentData(imageData, mimeType: "image/jped", fileName: "image")
//Display the view controller
self.presentViewController(myMail, animated: true, completion: nil)
}
else{
var alert = UIAlertController(title: "Alert", message: "Your device cannot send emails", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
func mailComposeController(controller: MFMailComposeViewController!,
didFinishWithResult result: MFMailComposeResult,
error: NSError!){
switch(result.value){
case MFMailComposeResultSent.value:
println("Email sent")
default:
println("Whoops")
}
self.dismissViewControllerAnimated(true, completion: nil)
}
}
आप सेट नहीं 'mailComposeDelegate' छोड़ने की ज़रूरत परीक्षण करने के लिए। – rmaddy