Skip to main content

login

Description

info

User login. You must wait for the success callback (not just a successful return) before calling other APIs. You need to call the login API in the following scenarios:
(1) After the APP starts, retrieve a new token from the server;
(2) After the token expires post-login, retrieve a new token from the server;
(3) After being forcefully logged out by the APP administrator, retrieve a new token from the server;
(4) After the user voluntarily logs out, retrieve a new token from the server.

You do NOT need to call the login API in the following scenarios:
(1) The user's network disconnects and reconnects;
(2) While a login process is already underway and not yet completed.

Note

(1) If a failure callback occurs, retrying is meaningless. View the error message, check parameters, adjust the code, and then continue;
(2) In one App, the SDK does not support logging in with multiple accounts at the same time. You must call logout first before logging into another account;
(3) With the exception of setting listeners, initialization, and getting the login status, all other APIs must be called only after the SDK login callback succeeds;
(4) A successful login callback may not mean the IM login is truly successful. You need to observe the IM connection status callback. Only when onConnectSuccess is received does it mean login and connection to the IM are successful.

Related Callbacks:
onConnectFailed
onConnecting
onConnectSuccess
onUserTokenExpired

Function Prototype

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

Input Parameters

Parameter NameParameter TypeRequiredDescription
operationIDNSStringNoOperation ID, used to pinpoint issues, keep unique, prefer time+random
userIDNSStringYesIM user userID
tokenNSStringYesOpenIM user token, obtained via user_token after business backend validates credentials

Return Result

Parameter NameParameter TypeDescription
onSuccessOIMSuccessCallbackSuccess return
onFailureOIMFailureCallbackFailure return

Code Example


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