Init
introduction
Init IM SDK
Prepare a SDKAppID.
json_sdk_config can be NULL, null string pointer or "" empty string. They are all default value for SdkConfig.
Every Json key in json_sdk_config is optional, please check SdkConfig
sdk_config_config_file_path and sdk_config_log_file_path must be encoded in UTF-8
The sdk_config_config_file_path and sdk_config_log_file_path paths require the application to have read and write permissions.
After the SDK is initialized successfully, you need to add the required event listener to avoid missing messages.
Parameter details
Parameter name | Parameter type | Required | Description |
---|---|---|---|
sdk_app_id | long | yes | sdk_app_id is automatically generated after create an IM instance on the IM Console |
json_sdk_config | SdkConfig | yes | IM SDK Init config |
Returned template
TIMResult
Return value details
name | type | description |
---|---|---|
TIMResult | TIMResult | Return value of calling API |
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;
using EasyUI.Toast;
public class InitSDK : 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(Init);
Copy.onClick.AddListener(CopyText);
}
public void Init()
{
var sdkappid = PlayerPrefs.GetString("Sdkappid", "");
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 == "")
{
Toast.Show("Input sdkappid first");
return;
}
TIMResult res = TencentIMSDK.Init(long.Parse(sdkappid), sdkConfig);
Result.text = Utils.SynchronizeResult(res);
}
void CopyText()
{
Utils.Copy(Result.text);
}
void OnApplicationQuit()
{
TencentIMSDK.Uninit();
}
}