Skip to main content
Version: v4

Login Listeners

CometChat SDK provides you with a mechanism to get real-time status whenever a user logs into CometChat or logs out from CometChat.

Login Listener provides you with the below 4 methods:

Delegate MethodInformation
onLoginSuccess(user: User)This method is triggered when the user successfully logs into the CometChat SDK. It returns an Object of the User loggedIn.
onLoginFailed(error: CometChatException?)This method is triggered when the user could not successfully log into the CometChat SDK. It returns an Object of the CometChatException.
onLogoutSuccess()This method is called when the user successfully logs out from the CometChat SDK. It does not return anything.
onLogoutFailed(error: CometChatException?)This method is triggered when the user could not successfully log out of the CometChat SDK. It returns an Object of the CometChatException.

In order to use the Delegate methods you must add protocol conformance CometChatLoginDelegate as CometChat.logindelegate = self . Here is the example of CometChatLoginDelegate:

extension AppDelegate: CometChatLoginDelegate {

func onLoginSuccess(user: User) {
print("Login Success")
}

func onLoginFailed(error: CometChatException?) {
print("Login Failed")
}

func onLogoutSuccess() {
print("Logout Success")
}

func onLogoutFailed(error: CometChatException?) {
print("Logout Failed")
}
}