Login

introduction

Login

Only the conversation acquisition API can be called immediately after you call the login API, and other APIs can be called only after you have successfully logged in to the SDK. Therefore, make sure that you have logged in successfully before using other features; otherwise, such features may become abnormal or unavailable.

User needs to login to Tencent Cloud IM server to communicate, and for login you need to fill out UserID and UserSig, more details please check Login Authentication

Login before the following scenarios

First calling IM SDK functions after APP launched.

Credential expired when login, Login callback returns ERR_USER_SIG_EXPIRED(6206) or ERR_SVR_ACCOUNT_USERSIG_EXPIRED(70001) error code, and you need to generate new userSig and relogin.

Credential expired when logged in, user will receive UserSigExpiredCallback callback, and you need to generate new userSig and relogin.

Kicked offline, kicked offline when logged in, IM SDK will inform you by KickedOfflineCallback, you may notify users to Login again.

No Login before the following scenarios

Network reconnected, don't 'Login' and IM SDK will back online automatically.

When logging, don't repeat logging in.

Once logged in, DAU is start counting. Please double check your login scenarios to prevent hyper DAU.

You don't need to sign up on your first login, as you will automatically sign up if the login is successful.

Within the same APP, IM SDK doesn't allow multi-logged in. If logged in multiple times simultaneously, only the last one will stay online.

You can configure multi-client login policies for the IM SDK in the Tencent Cloud console.

There are multiple multi-client login policies, such as A user can be concurrently online on a mobile or desktop platform and the web platform or A user can be concurrently online on all platforms.

For more information on the configuration, see Feature Configuration.

You can configure the Max Login Instances per User per Platform for the IM SDK in the Tencent Cloud console, that is, the maximum number of instances on the same platform that can be concurrently online.

This feature is available only for the Ultimate edition. A user can be concurrently online on up to ten clients on the web platform or on up to three clients on the Android, iPhone, iPad, Windows, or macOS platform (the maximum number of clients that can be concurrently online on Flutter is subject to the actual compilation result).

For more information on the configuration, see Feature Configuration.

When you call the Login API to log in, if the limit specified by the multi-client login policy for your account is exceeded, a newly logged in instance will kick out an earlier one.

The one kicked out will receive KickedOfflineCallback.

Call Login to switch between accounts in the application.

For example, to switch the logged-in user from Alice to Bob, just call Login bob. You don't need to explicitly call logout alice, as this operation will be handled automatically inside the IM SDK.

Parameter details

overload1

Parameter name Parameter type Required Description
user_id string Required user ID
user_sig string Required Generated by sdk_app_id and secret, see https://www.tencentcloud.com/document/product/1047/34385
callback NullValueCallback Required Asynchronous callback

overload2

Parameter name Parameter type Required Description
user_id string Required user ID
user_sig string Required Generated by sdk_app_id and secret, see https://www.tencentcloud.com/document/product/1047/34385
callback ValueCallback< string > Required Asynchronous callback The format of json_param in the return value is string

Returned template

TIMResult

The parameters of the callback function after successfully calling the API:
code:int
desc:string
json_param:'' // json_ Params is an empty string ""
user_data:string

Return value details

name type description
TIMResult TIMResult Return value of calling API
code int Result error code: Error Codes
desc string The description of the error.
json_param string Json string. Calling different API will get different Json strings.
user_data string User-defined data transfered by ImSDK without any processing

Code example

using UnityEngine;
using UnityEngine.UI;
using com.tencent.im.unity.demo.types;
using com.tencent.imsdk.unity;
using com.tencent.imsdk.unity.types;
using com.tencent.imsdk.unity.enums;
using com.tencent.im.unity.demo.utils;

public class Login : MonoBehaviour
{
  public Text Header;
  public Text Result;
  public Button Submit;
  public Button Copy;

  void Start()
  {
    Result = GameObject.Find("ResultText").GetComponent<Text>();
    Header = GameObject.Find("HeaderText").GetComponent<Text>();
    Submit = GameObject.Find("Submit").GetComponent<Button>();
    if (CurrentSceneInfo.info != null)
    {
      Header.text = Utils.IsCn() ? CurrentSceneInfo.info.apiText + " " + CurrentSceneInfo.info.apiName : CurrentSceneInfo.info.apiName;
      Submit.GetComponentInChildren<Text>().text = CurrentSceneInfo.info.apiName;
    }
    Copy = GameObject.Find("Copy").GetComponent<Button>();
    Copy.GetComponentInChildren<Text>().text = Utils.t("Copy");
    Submit.onClick.AddListener(LoginSDK);
    Copy.onClick.AddListener(CopyText);
  }
  void LoginSDK()
  {
    var userid = PlayerPrefs.GetString("UserID", "");
    var user_sig = PlayerPrefs.GetString("Secret", "");
    TIMResult res = TencentIMSDK.Login(userid, user_sig, Utils.addAsyncNullDataToScreen(GetResult));
    Result.text = Utils.SynchronizeResult(res);
  }

  void GetResult(params object[] parameters)
  {
    Result.text += (string)parameters[0];
  }

  void CopyText()
  {
    Utils.Copy(Result.text);
  }
  void OnApplicationQuit()
  {
    TencentIMSDK.Uninit();
  }
}

results matching ""

    No results matching ""