You need to initialize and log in to the IM Unity SDK before use. The SDK is initialized with the following code in Unity after integration:
public static void Init() {
SdkConfig sdkConfig = new SdkConfig();
sdkConfig.sdk_config_config_file_path = Application.persistentDataPath + "/TIM-Config";
sdkConfig.sdk_config_log_file_path = Application.persistentDataPath + "/TIM-Log";
if (sdkappid == "")
{
return;
}
TIMResult res = TencentIMSDK.Init(long.Parse(sdkappid), sdkConfig);
}
SDKAppID
is the unique ID that the IM service uses to identify a customer account. We recommend you apply for a new SDKAppID
for every independent app to automatically isolate messages between SDKAppIDs
.
You can view all SDKAppIDs
in the IM console or click Create Application to create an SDKAppID
.
It is used to configure the storage path of IM running logs and data.
Storage path of local IM data.
Note:The app needs to have read-write access to this path.
Routine storage path of IM data.
Note:The app needs to have read-write access to this path.
It is used to display the result returned when the SDK is called. When res
is TIMResult.TIM_SUCC = 0
, the API call is successful.
After the SDK is successfully initialized, add required listeners to avoid missing messages.
public static void Login() {
if (userid == "" || user_sig == "")
{
return;
}
// You can replace with your own sdkappid
TIMResult res = TencentIMSDK.Login(userid, user_sig, (int code, string desc, string json_param, string user_data)=>{
});
}
The unique ID for user login. You are advised to enter only letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-). Its length cannot exceed 32 bytes.
Login ticket of the IM SDK. It is calculated by your business server to ensure security. For more information on the calculation method, see Generating UserSig.
onUserSigExpired
callback. That is, when the UserSig
expires, you need to use a new UserSig
for login.onKickedOffline
callback. That is, when the current user is kicked offline, the "You have already logged in to the SDK on another device using the current account. Are you sure you want to log in again?" message can be displayed on the UI. In this case, you can select "Yes" to log in again.login
function because the SDK automatically goes online.You cannot use the same account to log in on two mobile phones of the same model. For example, you cannot use the same account for login on two iPhones. However, one Android phone and one iPhone are considered as two different devices, and you can use the same account to log in on these two devices. For more information on configurations related to multi-client login, see the Login settings section in Feature Configuration.
To log out, call the Logout
function.
public static void Logout() {
TIMResult res = TencentIMSDK.Logout((int code, string desc, string json_param, string user_data)=>{
});
}
After you log in successfully by calling IM SDK Login
, DAU will be calculated. Use IM SDK Login
appropriately according to the business scenarios to avoid an excessively high DAU.
Was this page helpful?