MFMailComposeViewController error [MC] Filtering mail sheet accounts for bundle ID

梦想与她 提交于 2019-12-10 02:19:12

问题


I do the standard functionality of sending messages with MFMailComposeViewController.

My code:

if MFMailComposeViewController.canSendMail()
{
    let mail = MFMailComposeViewController()
    mail.mailComposeDelegate = self
    mail.setToRecipients(["someemail@gmail.com"])
    mail.setSubject("Subject")
    mail.setMessageBody("Some Text", isHTML: false)
    self.presentViewController(mail, animated: true, completion: nil)
}

Controller do not open and I see a message in the console that have never seen.

[MC] Filtering mail sheet accounts for bundle ID: [My Bundle ID], source account management: 1

[MC] Result: NO

Help please.


回答1:


If a mail account has been set at the device where you try to test your application there is no problem. Please create a mail account.




回答2:


For Swift 3.0.1 - 4.2 Compatible

if MFMailComposeViewController.canSendMail()
{
    let mail = MFMailComposeViewController()
    mail.mailComposeDelegate = self
    mail.setToRecipients(["someemail@gmail.com"])
    mail.setSubject("Subject")
    mail.setMessageBody("Some Text", isHTML: false)
    self.present(mail, animated: true, completion: nil)
}

I had the same error though it works perfectly on my device with iOS 10.1.1. I had a similar problem and found that the Mail Composer would only work on iOS 9 in the simulator, there is some sort of bug with iOS 10 and running Mail Composer on the simulator with my current knowledge.

Update I have also tested this with a device with iOS 11.4 and got the same results.

Tried these calls to open mail on the simulator and they did not work. Though work they work fine on a real device.

UIApplication.shared.keyWindow?.rootViewController?.present(mail, animated: true)
self.navigationController?.present(mail, animated: true, completion: nil)



回答3:


Had the same problem. It was connected with presenter.

You need to present MFMailComposeViewController from UINavigationController. Try this:

self.navigationController.presentViewController(mail, animated: true, completion: nil)

It solved my problem.




回答4:


If you check the value of MFMailComposeViewController.canSendMail(), you will see that it is false. So that the code inside your if statement would not get executed. And to return true, you need to enable one email on your mobile phone.




回答5:


You need to Login in 'Mail' App in order to present the Mail Composer.




回答6:


For me this answer solved the problem. I had the same issue on a real device with active mail accounts and changed the presenting view controller to

        let mailComposeViewController = MFMailComposeViewController()
        mailComposeViewController.mailComposeDelegate = self
        mailComposeViewController.setToRecipients([address])
        mailComposeViewController.setMessageBody(message, isHTML: false)
        mailComposeViewController.setSubject(subject)


        UIApplication.shared.keyWindow?.rootViewController?.present(mailComposeViewController, animated: true)



回答7:


@IBAction func gmailButton(_ sender: UIButton){
    self.popUp()
}

func popUp(){
    guard MFMailComposeViewController.canSendMail() else {
        return
    }

    let composer = MFMailComposeViewController()
    composer.mailComposeDelegate = self
    composer.setToRecipients(["helpdesk@gmail.com"])
    composer.setSubject("succes")
    composer.setMessageBody("succes sent", isHTML: false)
    present(composer, animated: true)
}

First you have to log in to Gmail, after that this program can be used. don't forget use real device to try this



来源:https://stackoverflow.com/questions/40608727/mfmailcomposeviewcontroller-error-mc-filtering-mail-sheet-accounts-for-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!