logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Offline login


Function introduction

Offline login is typically used when the application is cleared from memory, and the user relaunches the application by clicking on the application icon. In this scenario, the user can directly access the local SDK data without network connectivity or a successful login.

Note

Users can only perform an offline login using the UserID from their previous successful login; otherwise, the login will not succeed.

Technical principle

When the offline login interface is called, the ZIM SDK performs verification (UserID verification; if token-based login is used, it also verifies the token's validity period). After successful verification, the SDK returns a login success callback, allowing users to query local data, while the SDK internally attempts to establish a connection with the backend service automatically.

Procedure

1. Log in to the app in offline status

If the network is disconnected and the app is logged out, create the ZIMLoginConfig class first, set the isOfflineLogin parameter to true, and call the login method to pass in ZIMLoginConfig to log in to the app with the user information for the previous login. Local data of the SDK is accessible if the login is successful as indicated in the ZIMLoggedInCallback callback.

Note

We recommend that you cache user information for each login. If the app is opened, the following logic is implemented when reading the cache:

  • If the user does not log in with the UserID for the previous online login, isOfflineLogin should be false. In this case, offline login is not supported, and local data of the SDK is inaccessible.
  • If the user logs in with the UserID for the previous online login, isOfflineLogin should be true to implement automatic login, accelerated access to the app homepage, and UI rendering in advance. In this case, offline login is supported.

Login method definition

Sample code
ZIMLoginConfig config;
config.userName = user_name;
// Do not specify this parameter for AppSign-based authentication.
config.token = token;
config.isOfflineLogin = true;

zim.login("userID", config, new ZIMLoggedInCallback() {
     @Override
     public void onLoggedIn(ZIMError errorInfo) {
        // Offline login is successful, and local data of the SDK can be queried.
    }
}];
1
Copied!

2. Access local data of the SDK

After successful offline login, the following methods of the ZIM SDK 2.15.0 or earlier can be called when the network is disconnected.

CategoryMethod
User
Group
Message
Call invitationqueryCallInvitationList
Conversation

3. Listen for the login event

Listen for the onConnectionStateChanged event to obtain the status of connection between the ZIM SDK and the ZIM backend.

After a successful offline login, the value of ZIMConnectionState in onConnectionStateChanged is Connecting (enumeration value: 1).

You can call network methods to synchronize backend data only when the ZIM SDK automatically connects to the ZIM backend upon network reconnection and the value of ZIMConnectionState in onConnectionStateChanged is Connected (enumeration value: 2).

Previous

Multi-device login

Next

Blacklist management