V2TIMManager is a core class and also an entry class of the IM SDK. It implements features such as IM SDK initialization and login, message sending/receiving, group creation, and group leaving. To complete initialization, call the initSDK API.
// 1. Obtain the SDKAppID of the application from the IM console. For more information, see SDKAppID.
// 2. Initialize the `config` object.
V2TIMSDKConfig *config = [[V2TIMSDKConfig alloc] init];
// 3. Specify the log output level. For more information, see [SDKConfig](#SDKAppID).
config.logLevel = V2TIM_LOG_INFO;
// 4. Initialize the SDK and set the listening object of `V2TIMSDKListener`.
// After you call `initSDK`, the SDK automatically connects to the network. The network connection status can be listened to in the `V2TIMSDKListener` callback.
[[V2TIMManager sharedInstance] initSDK:1400000123 config:config listener:self];
// 5. Listen to the `V2TIMSDKListener` callback.
- (void)onConnecting {
// The SDK is connecting to the Tencent CVM instance.
}
- (void)onConnectSuccess {
// The SDK is successfully connected to the Tencent CVM instance.
}
- (void)onConnectFailed:(int)code err:(NSString*)err {
// The SDK fails to connect to the Tencent CVM instance.
}
The initialization API initSDK
contains three required parameters, including SDKAppID
, Config
, and listener
.
SDKAppID
is a unique ID that the IM service uses to identify a customer account. We recommend that 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 an Application to create an SDKAppID
.
The V2TIMSDKConfig
parameter is used for initialization configuration of the SDK. It is often used to set the log level, that is, the logLevel parameter. The following table lists the log levels.
Log Level | Log Output |
---|---|
V2TIM_LOG_NONE | No log is output. |
V2TIM_LOG_DEBUG | Logs of the DEBUG, INFO, WARNING, and ERROR levels are output. |
V2TIM_LOG_INFO | Logs of the INFO, WARNING, and ERROR levels are output. |
V2TIM_LOG_WARN | Logs of the WARNING and ERROR levels are output. |
V2TIM_LOG_ERROR | Logs of the ERROR level are output. |
/Library/Caches/
directory by default.python decode_mars_nocrypt_log_file.py imsdk_yyyyMMdd.xlog
V2TIMSDKListener is used to listen to the network status and changes to the user information.
Event Callback | Event Description | Recommended Operation |
---|---|---|
onConnecting | The SDK is connecting to the CVM instance. | The "Connecting" status can be displayed on the UI. |
onConnectSuccess | The SDK is successfully connected to the CVM instance. | - |
onConnectFailed | The SDK fails to connect to the CVM instance. | The user can be notified that the network connection is currently unavailable. |
onKickedOffline | 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. |
onUserSigExpired | The UserSig expires. | Use the new UserSig for login. |
onSelfInfoUpdated | The information of the current user is updated. | Update your own profile photo and nickname on the UI. |
Note:If you receive the
onUserSigExpired
callback, the UserSig that you use for login has expired. In this case, you need to update the UserSig and then log in again. If you continue to use the expired UserSig, the SDK falls into an endless login loop.
You can call the login(userID, userSig) function of V2TIMManager
to log in to the SDK. Features of the IM SDK are available to you only after you successfully log in to the SDK.
Note:After you log in successfully by calling
IM SDK Login
, DAU will be calculated. Please useIM SDK Login
appropriately according to the business scenario to avoid an excessively high DAU.
login
function in the following scenarios:onUserSigExpired
callback. That is, when the UserSig expires, you need to use the new UserSig for login.onKickOffline
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.You do not need to call the login
function in the following scenarios:
login
function as 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 Apple mobile phones. However, one Android mobile phone and one Apple mobile phone will be 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-device login, see the Login settings section in Feature Configuration.
To log out of the SDK, call the logout() function.
Was this page helpful?