logout
Description
The APP needs to wait for the logout callback to succeed.
After a successful logout, you will no longer receive new messages sent by others.
If switching accounts, you need to wait for user A's logout callback to succeed before calling user B's login, otherwise the login may fail.
If the APP lifecycle is consistent with the SDK lifecycle, you can call logout when the user exits the APP.
(1) When receiving onKickedOffline and onUserTokenExpired from the SDK, it means being kicked offline, the token is invalid, or the token has expired.
After the SDK triggers this internally, it will automatically call logout, so there is no need to make an external call to the logout function.
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<dynamic> logout({String? operationID})
Input Parameters
None
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| ~ | ~ | Operation successful if no exception thrown |
Code Example
await OpenIM.iMManager.logout();
//todo
Function Prototype
- (void)logoutWithOnSuccess:(nullable OIMSuccessCallback)onSuccess
onFailure:(nullable OIMFailureCallback)onFailure;
Input Parameters
None
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| onSuccess | OIMSuccessCallback | Success return |
| onFailure | OIMFailureCallback | Failure return |
Code Example
[OIMManager.manager logoutWithOnSuccess:^(NSString * _Nullable data) {
} onFailure:^(NSInteger code, NSString * _Nullable msg) {
}];
Function Prototype
public void logout(OnBase<String> base)
Parameter Details
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| base | OnBase | Yes | Callback interface |
Code Example
OpenIMClient.getInstance().logout(new OnBase<String>() {
@Override
public void onError(int code, String error) {
// Logout failed
}
@Override
public void onSuccess(String data) {
// Logout succeeded
}
});
Function Prototype
IMSDK.logout(): Promise<WsResponse>;
Input Parameters
None
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<WsResponse> | Success callback |
| Promise.catch() | Promise<WsResponse> | Failure callback |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();
const status = IMSDK.logout()
.then(() => {
// Logout successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
IMSDK.asyncApi('logout',operationID: string): Promise<void>;
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| operationID | string | Yes | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
Return Result
Use the
openim-uniapp-polyfillpackage to make the function Promise. When calling, you need to usethenandcatchto determine and handle success and failure callbacks.
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<void> | Success callback |
| Promise.catch() | Promise<CatchResponse> | Failure callback |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('logout', IMSDK.uuid())
.then(() => {
// Logout successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDK.logout(operationID?: string): Promise<void>
Parameter Details
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| operationID | string | No | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<void> | Success callback |
| Promise.catch() | Promise<OpenIMApiError> | Failure callback |
Code Example
import OpenIMSDK from "@openim/rn-client-sdk";
OpenIMSDK.logout()
.then(() => {
// Logout successful
})
.catch((error) => {
// Call failed
});