logout
Log out
Feature Introduction
Apps should wait for the logout callback to succeed. After a successful logout, you will no longer receive new messages sent by others. If you are switching accounts, wait for the logout callback of user A to succeed before calling the login for user B, otherwise, the login might fail. If the app's lifecycle is consistent with the SDK's lifecycle, call logout when the user exits the app.
(1) When receiving OnKickedOffline and OnUserTokenExpired from the SDK, indicating being kicked offline, an invalid token, or an expired token, the SDK will automatically trigger and call logout internally. There's no need to call the logout function externally.
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<dynamic> logout({String? operationID})
Input Parameters
None
Return Results
Parameter Name | Parameter Type | Description |
---|---|---|
~ | ~ | No exceptions means successful logout |
Code Example
await OpenIM.iMManager.logout();
//todo
Function Prototype
- (void)logoutWithOnSuccess:(nullable OIMSuccessCallback)onSuccess
onFailure:(nullable OIMFailureCallback)onFailure;
Input Parameters
None
Return Results
Parameter Name | Parameter Type | Description |
---|---|---|
onSuccess | OIMSuccessCallback | Successful return |
onFailure | OIMFailureCallback | Failed return |
Code Example
[OIMManager.manager logoutWithOnSuccess:^(NSString * _Nullable data) {
} onFailure:^(NSInteger code, NSString * _Nullable msg) {
}];
Function Prototype
public void logout(OnBase<String> base)
Detailed Parameters
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 successful
}
});
Function Prototype
IMSDK.logout(): Promise<WsResponse>;
Input Parameters
None
Return Results
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse> | Successful callback |
Promise.catch() | Promise<WsResponse> | Failed 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(() => {
// Successful logout
})
.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, for problem location, unique, suggested to use current time and random number |
Return Results
With the
openim-uniapp-polyfill
package, the function is made into a Promise. When calling, usethen
andcatch
to determine and handle successful and failed callbacks.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<void> | Successful callback |
Promise.catch() | Promise<CatchResponse> | Failed callback |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('logout', IMSDK.uuid())
.then(() => {
// Successful logout
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDKRN.logout(operationID: string): Promise<void>
Parameter详解
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
operationID | string | Yes | Operation ID, used for problem location, keep unique, suggest using current time and random number |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<void> | Callback on successful call |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.logout("operationID")
.then(() => {
// Successful logout
})
.catch(({ errCode, errMsg }) => {
// Call failed
});