I am using MailCore 2 iOS IMAP source to have IMAP mail access. I added mail folder list etc. features in that. I want to provide "Sign Out" feature for any imap mail that logged-in. Could anyone advise me, how to clear the existing login session and do sign out successfully?
Sign Out feature MailCore 2 iOS IMAP
294 Views Asked by Stella At
2
There are 2 best solutions below
0
On
Sample code that working for me
IMAPSessionHelper.swift
class IMAPSessionHelper: NSObject {
fileprivate static var privateShared: IMAPSessionHelper?
var imapSession: MCOIMAPSession!
class func shared() -> IMAPSessionHelper {
guard let uwShared = privateShared else {
privateShared = IMAPSessionHelper()
return privateShared!
}
return uwShared
}
class func destroy() {
privateShared = nil
}
private override init() {
imapSession = MCOIMAPSession()
imapSession.hostname = _IMAP_HOST_NAME
imapSession.port = _IMAP_PORT
imapSession.connectionType = .TLS
}
func config(with account: Account) {
imapSession.username = account.email
imapSession.password = account.password
}
}
Logout:
fileprivate func logout() {
let logout = IMAPSessionHelper.shared().imapSession.disconnectOperation()
logout?.start({ (error) in
if let error = error {
logger(error.localizedDescription)
return
}
IMAPSessionHelper.destroy()
_ = self.navigationController?.popToRootViewController(animated: true)
})
}
Use the
disconnectOperationon your session.Sample (Swift):
This logs out the session. You will then need to take care of your local store (deleting your session object, messages etc.). Here's some documentation on it.