V2TIMManager is a core class and also an entry class of the IM SDK. It implements features including IM SDK initialization and login, message sending and receiving, group creation, and group quitting. To complete initialization, call the initSDK API.
// 1. Obtain the SDKAppID of the app 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 monitored in the V2TIMSDKListener callback.
[[V2TIMManager sharedInstance] initSDK:1400000123 config:config listener:self];
// 5. Monitor the V2TIMSDKListener callback.
- (void)onConnecting {
// The SDK is connecting to the Tencent CVM instance.
}
- (void)onConnectSuccess {
// The SDK has successfully connected to the Tencent CVM instance.
}
- (void)onConnectFailed:(int)code err:(NSString*)err {
// The SDK failed to connect to the Tencent CVM instance.
}
The initialization API, initSDK (SDKAppID, SDKConfig, listener), contains three required parameters: SDKAppID
, Config
, and listener
.
SDKAppID indicates the app ID. It 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. Alternatively, you can create an SDKAppID by clicking Add Application.
The V2TIMSDKConfig
parameter is used for initialization configuration of the SDK. It is often used to set the log level, that is, logLevel. The following table describes possible 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 monitor the network status and user information changes.
Event Callback | Event Description | Recommended Operation |
---|---|---|
onConnecting | The SDK is connecting to the CVM instance. | Display the "Connecting" state on the UI. |
onConnectSuccess | The SDK has 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 was forced offline. | Display the message stating "You have already logged in to the SDK on another device using the current account. Are you sure you want to log in again?" on the UI. |
onUserSigExpired | The UserSig has expired. | Use the new UserSig for login. |
onSelfInfoUpdated | The information of the current user was updated. | Update your own profile photo and nickname on the UI. |
Note:
If the
onUserSigExpired
callback is received, in indicates that the UserSig used 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.
You need to call the 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 forced offline, the message stating "You have already logged in to the SDK on another device using the current account. Are you sure you want to log in again?" 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 Login Settings.
To log out of the SDK, call the logout() function.
Was this page helpful?