2017-08-09 69 views
1

我是IOS编程的新手,所以我不确定这是编程主题还是其他复杂的东西,但我想为我的应用程序添加反馈功能。也就是说,我正在考虑设置一个名为“FeedBack”的按钮,当用户点击它时,将它们重定向到他们的本地电子邮件应用程序,其中'to'部分已经填充了我的凭证。有关我如何做到这一点的任何建议?将反馈功能添加到应用程序

+1

使用'MFMailComposeViewController'错误发送邮件。 – rmaddy

回答

1

只为您的信息,你不能从模拟器,因此给出了处理这里试试下面的代码

import Foundation 
    import MessageUI 
    import UIKit 

    class test: UIViewController, MFMailComposeViewControllerDelegate { 
     override func viewDidLoad() { 
      super.viewDidLoad() 
      if MFMailComposeViewController.canSendMail() 
      { 
      sendEmail() 

      }   
      else 
      { 
       print("Mail services are not available") 
       return 
      } 

     } 

     func sendEmail() {  
      let composeVC = MFMailComposeViewController() 
      composeVC.mailComposeDelegate = self 

      composeVC.setToRecipients(["[email protected]"]) 
      composeVC.setSubject("Any subject!") 
      composeVC.setMessageBody("this is your message body!", isHTML: false) 
      // Present the view controller modally. 
      self.present(composeVC, animated: true, completion: nil) 
     } 

     func mailComposeController(controller: MFMailComposeViewController, 
           didFinishWithResult result: MFMailComposeResult, error: NSError?) { 

      controller.dismiss(animated: true, completion: nil) 
     } 


    } 
+0

谢谢你的回应。从你的代码中,我明白我必须在Storyboard中创建另一个View Controller,这是否正确?或者我只是在没有Storyboard对应的情况下实现它? –

+0

不,不需要创建新的控制器 您只需要在viewcontroller中实现委托方法,您可以从该控制器移动到邮件应用程序 –

+0

我将使用哪种委托方法?对不起,我是编程新手。另外,如何仅在单击按钮时调用此方法? –