MFMailComposeViewController不会关闭(iOS10)

时间:2016-09-21 01:29:07

标签: ios swift xcode email mfmailcomposeviewcontroller

我希望你很好。

我对Swift很新。我使用iOS10 SDK在XCode 8.0上构建了一个iOS应用程序。我正在尝试添加允许用户向预配置的电子邮件地址发送电子邮件的功能。点击发送按钮时,MFMailComposeViewController正常打开,用户可以通过添加的邮件帐户发送或取消。单击发送实际上会正常发送电子邮件,但MFMailComposeViewController在发送电子邮件或单击取消按钮后不会关闭。请帮忙!

由于

minmag = 5
maxmag = 7

mindist = 25
maxdist = 64

filter = np.zeros((1, 7), dtype='object')
add = np.zeros((1, 7), dtype='object')
k = 0

for i in range(0,len(lists)):
    if lists[i, 4]>= minmag and lists [i, 4] <= maxmag and lists [i, 6]>=mindist and  lists [i, 6]<= maxdist:
        if k == 0:
            for x in range(0,16):
                filter[0, x] = lists[i, x]
            k = 1
        else:
            for x in range(0, 16):
                add[0, x] = lists[i, x]
            filter = np.append(filter, add, axis=0)

1 个答案:

答案 0 :(得分:1)

用此替换完整的代码。

import UIKit
import MessageUI

class EmailHelpdesk_ViewController: UIViewController, MFMailComposeViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

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

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //Email Subject and Body text fields.
    @IBOutlet var helpdesk_email_subject: UITextField!
    @IBOutlet var helpdesk_email_body: UITextView!

    var mail_controller_compose:MFMailComposeViewController!

    //Helpdesk (Submit Button - Config)
    @IBAction func helpdesk_email_send(_ sender: AnyObject) {
        let HDsubjectText = helpdesk_email_subject.text
        let HDbodyText = helpdesk_email_body.text

        //MFMailComposeViewController to be called.
        mail_controller_compose = MFMailComposeViewController()
        mail_controller_compose.mailComposeDelegate = self

       mail_controller_compose.setToRecipients(["example@example.com"])
        mail_controller_compose.setSubject(HDsubjectText!)
        mail_controller_compose.setMessageBody(HDbodyText!, isHTML: false)


        self.present(mail_controller_compose, animated: true, completion: nil)
    }

    func mailComposeController(controller: MFMailComposeViewController,
        didFinishWithResult result:MFMailComposeResult, error: NSError?)     {
         mail_controller_compose.dismiss(animated: true, completion: nil)
    }
}

尝试一次。