Check if connection for imapsession is established

83 Views Asked by At

I am trying to check if the connection for imapsession is established. If it is established then the user should move on the next ViewController but if the connection is failed then it shows an error.

I am new to MailCore and there is not much documentation and guides so I couldn't find any information on how to code it.

Though I tried something myself:

var imapsession:MCOIMAPSession = MCOIMAPSession()
var checkAccount:MCOIMAPOperation = MCOIMAPOperation()

@IBAction func button1(_ sender: Any) {
       checklogin()
}

func checkLogin() {
    imapsession.hostname = "hostname"// String
    imapsession.username = usr // String
    imapsession.password = psw // String
    imapsession.port = port // UInt32 number
    imapsession.authType = MCOAuthType.saslPlain
    imapsession.connectionType = MCOConnectionType.TLS
    checkAccount.start({ (error) in
        if let error = error {
            print("error connecting")
            print(error)
        } else {
            self.performSegue(withIdentifier: "TabSegue", sender: self)
        }
    })
}

Any ideas on how to do it in a proper way?

1

There are 1 best solutions below

0
DrueTrue On

I found out a solution, it is pretty easy.

let checkOperation = imapsession.checkAccountOperation()
    checkOperation?.start({ (error) in
        if error == nil {
            // success
        } else {
            print(error)
        }
    })