SDKAppID
.V2TIMSDKConfig
object.initSDK
to initialize the SDK.SDKAppID
uniquely identifies an account. We recommend you apply for a new SDKAppID
for each application. Messages are naturally isolated and cannot communicate between different SDKAppID
values. To perform the initialization, you must have a correct SDKAppID
.
In the Chat Console, you can view all your SDKAppID
values, and you can click Create Application to create an SDKAppID
.
V2TIMSDKConfig
V2TIMSDKConfig
object (Android / iOS and macOS / Windows), which is used to configure the SDK initially, such as setting the log level and log listening callback.Log Level | Log Output |
V2TIM_LOG_NONE | No log is output. |
V2TIM_LOG_DEBUG | Logs at the DEBUG, INFO, WARNING, and ERROR levels are output (default log levels). |
V2TIM_LOG_INFO | Logs at the INFO, WARNING, and ERROR levels are output. |
V2TIM_LOG_WARN | Logs at the WARNING and ERROR levels are output. |
V2TIM_LOG_ERROR | Logs at the ERROR level are output. |
/sdcard/tencent/imsdklogs/application package name
directory for versions earlier than v4.8.50 and in the /sdcard/Android/data/package name/files/log/tencent/imsdk
directory for v4.8.50 or later./Library/Caches/com_tencent_imsdk_log
directory.C:\\App
directory, SDK will store logs in the C:\\App\\com_tencent_imsdk_log
directory.python decode_mars_nocrypt_log_file.py imsdk_yyyyMMdd.xlog
setLogListener
(Android / iOS and macOS / Windows) to set a log listener.
After it is set, the SDK will throw log information through this callback in real time.V2TIMSDKConfig
is as follows:// Initialize the `config` objectV2TIMSDKConfig config = new V2TIMSDKConfig();// Specify the log output levelconfig.setLogLevel(V2TIMSDKConfig.V2TIM_LOG_INFO);// Specify the log listenerconfig.setLogListener(new V2TIMLogListener() {@Overridepublic void onLog(int logLevel, String logContent) {// `logContent` is the SDK log content}});
// Initialize the `config` objectV2TIMSDKConfig *config = [[V2TIMSDKConfig alloc] init];// Specify the log output levelconfig.logLevel = V2TIM_LOG_INFO;// Set the log listenerconfig.logListener = ^(V2TIMLogLevel logLevel, NSString *logContent) {// `logContent` is the SDK log content};
class LogListener final : public V2TIMLogListener {public:LogListener() = default;~LogListener() override = default;void OnLog(V2TIMLogLevel logLevel, const V2TIMString& logContent) override {// `logContent` is the SDK log content}};// Note that `logListener` should not be released before the SDK is uninitialized,// otherwise the log callback cannot be called.LogListener logListener;// Initialize the `config` objectV2TIMSDKConfig config;// Specify the log output levelconfig.logLevel = V2TIMLogLevel::V2TIM_LOG_INFO;// Specify the log listenerconfig.logListener = &logListener;
V2TIMSDKListener
.
We recommend you call the addIMSDKListener
API (Android / iOS and macOS / Windows) to add an SDK event listener and perform logic processing in the corresponding callback.V2TIMSDKListener
callbacks are as follows:Event Callback | Description | Recommended Operation |
onConnecting | The SDK is connecting to the CVM instance. | Display the "connecting" status on the UI. |
onConnectSuccess | The SDK is successfully connected to the CVM instance. | - |
onConnectFailed | The SDK failed to connect to the CVM instance. | Notify the user that the network connection is currently unavailable. |
onKickedOffline | The current user is kicked offline. | Display the "You are already logged in on another device. Are you sure you want to log in again?" message on the UI. |
onUserSigExpired | The login ticket expired. | Log in with a new UserSig . |
onSelfInfoUpdated | The current user's profile is updated. | Update the profile photo and nickname on the UI. |
onUserSigExpired
callback, the UserSig
that you use for login has expired. In this case, you need to use a new UserSig
to log in again. If you continue to use the expired UserSig
, the SDK will be in an infinite login loop.// The `sdkListener` type is `V2TIMSDKListener`.V2TIMManager.getInstance().addIMSDKListener(sdkListener);
// The `self` type is id<V2TIMSDKListener>.[[V2TIMManager sharedInstance] addIMSDKListener:self];
// `sdkListener` is an instance of V2TIMSDKListener.V2TIMManager::GetInstance()->AddSDKListener(&sdkListener);
initSDK
(Android / iOS and macOS / Windows) to initialize the SDK.// 1. Get the `SDKAppID` from the IM console.// 2. Initialize the `config` object.V2TIMSDKConfig config = new V2TIMSDKConfig();// 3. Specify the log output level.config.setLogLevel(V2TIMSDKConfig.V2TIM_LOG_INFO);// 4. Add the `V2TIMSDKListener` event listener. `sdkListener` is the implementation class of `V2TIMSDKListener`. If you don't need to listen to SDK events, skip this step.V2TIMManager.getInstance().addIMSDKListener(sdkListener);// 5. Initialize the SDK. You can call the login API as soon as you call this API.int sdkAppID = 1400000000; // please set the sdkAppID of your own applicationV2TIMManager.getInstance().initSDK(context, sdkAppID, config);
// 1. Get the `SDKAppID` from the IM console.// 2. Initialize the `config` object.V2TIMSDKConfig *config = [[V2TIMSDKConfig alloc] init];// 3. Specify the log output level.config.logLevel = V2TIM_LOG_INFO;// 4. Add the `V2TIMSDKListener` event listener. `self` is the implementation class of id<V2TIMSDKListener>. If you don't need to listen to SDK events, skip this step.[[V2TIMManager sharedInstance] addIMSDKListener:self];// 5. Initialize the SDK. You can call the login API as soon as you call this API.int sdkAppID = 1400000000; // please set the sdkAppID of your own application[[V2TIMManager sharedInstance] initSDK:sdkAppID config:config];
// 1. Get the `SDKAppID` from the IM console.// 2. Initialize the `config` object.V2TIMSDKConfig config;// 3. Specify the log output level.config.logLevel = V2TIMLogLevel::V2TIM_LOG_INFO;// 4. Add the `V2TIMSDKListener` event listener. `sdkListener` is the implementation class of `V2TIMSDKListener`.// If you don't need to listen to SDK events, skip this step.V2TIMManager::GetInstance()->AddSDKListener(&sdkListener);// 5. Initialize the SDK. You can call the login API as soon as you call this API.int sdkAppID = 1400000000; // please set the sdkAppID of your own applicationV2TIMManager::GetInstance()->InitSDK(sdkAppID, config);
addIMSDKListener
to add the SDK listener, call removeIMSDKListener
(Android / iOS and macOS / Windows) to remove it.unInitSDK
uninitialization API (Android / iOS and macOS / Windows).// Remove the `V2TIMSDKListener` event listener. `sdkListener` is the implementation class of `V2TIMSDKListener`.V2TIMManager.getInstance().removeIMSDKListener(sdkListener);// Uninitialize the SDKV2TIMManager.getInstance().unInitSDK();
// `self` is the implementation class of id<V2TIMSDKListener>.[[V2TIMManager sharedInstance] removeIMSDKListener:self];// Uninitialize the SDK[[V2TIMManager sharedInstance] unInitSDK];
// Remove the `V2TIMSDKListener` event listener. `sdkListener` is the instance of V2TIMSDKListener.V2TIMManager::GetInstance()->RemoveSDKListener(&sdkListener);// Uninitialize the SDKV2TIMManager::GetInstance()->UnInitSDK();
Was this page helpful?