2016-11-28 6 views
1

タップするとUIAlertViewを表示するアプリケーションにUIButtonがあります。アラートビューには、iOSのメール作成画面を開くボタンがあります。タイプ 'UIAlertControllerStyle.Type'の値を期待される引数タイプ 'UIAlertControllerStyle'に変換できません

メールの作成画面がうまく機能していますが、ユーザーがメールを送信したり「キャンセル」したりすると、メールの作成画面は消えません。私が使用しているコードは、私はこのエラーを取得していますように動作するようには思えない。

は予想引数の型に型「UIAlertControllerStyle.Type」の値を変換できません「UIAlertControllerStyle」

  var alert = UIAlertController(title: "Alert", message: "Your Device cannot send emails", preferredStyle: UIAlertControllerStyle) 

である場合がありますどのようなここにいる?ありがとう!

var myMail: MFMailComposeViewController! 

@IBAction func helpfeedbackAlert(_ sender: Any) { 

    if(MFMailComposeViewController.canSendMail()){ 
     myMail = MFMailComposeViewController() 

     myMail.setSubject("Test") 
     myMail.setToRecipients(["[email protected]"]) 

     self.present(myMail, animated: true, completion: nil) 
    } 
    else{ 
     var alert = UIAlertController(title: "Alert", message: "Your Device cannot send emails", preferredStyle: UIAlertControllerStyle) 
     self.present(alert, animated: true, completion: nil) 

    } 

} 

override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view.   
} 

func mailComposeController(controller: MFMailComposeViewController!, didFinishWith: MFMailComposeResult, error: NSError!){ 

    switch result.rawValue { 

    case MFMailComposeResult.cancelled.rawValue: 
     print("Mail cancelled") 

    case MFMailComposeResult.sent.rawValue: 
     print("Your email has been sent!") 

    case MFMailComposeResult.failed.rawValue: 
     print("Email has failed to send: %@", [error!.localizedDescription]) 
    default: 
     break 

    } 

    // Dismiss the mail compose view controller 
    controller.dismiss(animated: true, completion: nil) 


} 
+0

1つの問題とだけ関連するコードにあなたの質問を絞り込むください。あなたは2つの全く異なる問題と無関係なコードをあまりにも多く持っています。 – rmaddy

+0

@rmaddy確かに、私は投稿を編集しました。 – Miles

答えて

2

アラートの問題は簡単です。特定のアラートスタイル(.alert)を指定する必要がありますが、特定の値を渡すのではなく、列挙型の名前を渡しています。

メール作成者が解消しないという問題も簡単です。 mailComposeDelegateプロパティは決して設定しません。

switchの問題は、メソッドの署名が間違っていることです。

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) 

そして、rawValueのすべての使用の必要はありません。

+0

スイッチの修正がうまくいきます、ありがとう!アラートスタイルを特定し、mailComposeDelegateプロパティを設定するにはどうすればよいですか?私はすでにこのようにしていると思いました。if(MFMailComposeViewController.canSendMail()){ myMail = MFMailComposeViewController() – Miles

+0

私はすでにアラートスタイルにどのような値を使用しているかを示しました。メールデリゲートの場合、 'myMail.mailComposeDelegate = self'が必要です。 – rmaddy

+0

"UIAlertControllerStyle"を次のように置き換える必要があります:var .alert = UIAlertController(title: "Alert"、メッセージ: "あなたのデバイスはメールを送信できません"、preferredStyle:UIAlertControllerStyle) – Miles

1

VAR警告= UIAlertController(タイトル:「警告」、メッセージ:「お使いのデバイスは、電子メールを送信することはできません」、preferredStyle:.Alert)

関連する問題