Skip to main content

Login

Feature Introduction

Description

User login requires waiting for a successful callback (rather than a successful return) before calling other interfaces. You need to call the login interface in the following scenarios: 1) After the APP starts, and after retrieving a new token from the server. 2) After logging in, the token expires and a new token is retrieved from the server. 3) After being forcibly logged out by the APP administrator and a new token is retrieved from the server. 4) After the user actively logs out and a new token is retrieved from the server.

You don't need to call the login interface in the following scenarios: 1) When the user's internet disconnects and reconnects. 2) When a login process has not yet completed.

Note

1) If a failure callback appears, retrying is pointless. Check the error message, review the parameters, adjust the code, and continue. 2) Within an app, the SDK does not support logging in with multiple accounts simultaneously. You must log out first before logging in with another account. 3) Apart from setting listeners, initializing, and checking login status, all other interfaces must only be called after the SDK login callback is successful.

Function Prototype

- (void)login:(NSString *)userID
token:(NSString *)token
onSuccess:(nullable OIMSuccessCallback)onSuccess
onFailure:(nullable OIMFailureCallback)onFailure;

Input Parameters

Parameter NameParameter TypeMandatoryDescription
operationIDNSStringNoOperation ID for problem tracking. Keep unique, suggested to use current timestamp combined with a random number.
userIDNSStringYesIM user userID
tokenNSStringYesOpenIM user token. After backend verifies user credentials, it's obtained through user_token.

Return Result

Parameter NameParameter TypeDescription
onSuccessOIMSuccessCallbackSuccessful return
onFailureOIMFailureCallbackFailure return

Code Example


[OIMManager.manager login:@"" // userID obtained from your own business server
token:@"" // token acquired by business server from OpenIM server
onSuccess:^(NSString * _Nullable data) {
} onFailure:^(NSInteger code, NSString * _Nullable msg) {
}];