2017-08-09 15 views
1

私はIOSプログラミングの初心者ですので、これがプログラミングのようなものか複雑なものかどうかはわかりませんが、私のアプリケーションにフィードバック機能を追加したいと思います。つまり、「フィードバック」というボタンがあると考えています。ユーザーがそのボタンをクリックすると、「宛先」セクションが既に自分の資格情報で満たされているネイティブ電子メールアプリケーションにリダイレクトされます。どのように私がそれを行うことができるかについてのアドバイス?それはここで扱わエラーになりますので、あなたはシミュレータからメールを送信することはできませんちょうどあなたの情報のためアプリケーションにフィードバック機能を追加する

+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

ありがとうございます。あなたのコードから、私はストーリーボードに別のView Controllerを作成する必要があることを理解しています。ストーリーボードの対応なしで実装するだけですか? –

+0

いいえ新しいコントローラを作成する必要はありません メールアプリケーションに移動したビューコントローラにデリゲートメソッドを実装するだけです –

+0

どのデリゲートメソッドを使用しますか?申し訳ありませんが、私はプログラミングに慣れていません。また、ボタンをクリックしたときにのみこれを呼び出す方法はありますか? –

関連する問題