2017-08-09 46 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

我將使用哪種委託方法?對不起,我是編程新手。另外,如何僅在單擊按鈕時調用此方法? –

相關問題