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 Method | Information |
---|---|
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:
- Swift
- Objective C
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")
}
}
@interface ViewController ()<CometChatConnectionDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[CometChat logindelegate:self];
}
- (void)onLoginSuccess(user : User) {
NSLog(@"onLoginSuccess");
}
- (void)onLoginFailed(error : CometChatException) {
NSLog(@"onLoginFailed");
}
- (void)onLogoutSuccess() {
NSLog(@"onLogoutSuccess");
}
- (void)onLogoutFailed(error : CometChatException) {
NSLog(@"onLogoutFailed");
}