IMSDK
IM features a comprehensive suite of solutions including global access, one-to-one chat, group chat, message push, profile and relationship chain hosting, and account authentication. It also provides complete app access and backend management APIs.
V2TIMManager

Instance Methods

(BOOL) - initSDK:config:
 
(void) - addIMSDKListener:
 
(void) - removeIMSDKListener:
 
(void) - unInitSDK
 
(NSString *) - getVersion
 
(uint64_t) - getServerTime
 
(BOOL) - initSDK:config:listener:
 
(void) - login:userSig:succ:fail:
 
(void) - logout:fail:
 
(NSString *) - getLoginUser
 
(V2TIMLoginStatus- getLoginStatus
 
(void) - addSimpleMsgListener:
 
(void) - removeSimpleMsgListener:
 
(NSString *) - sendC2CTextMessage:to:succ:fail:
 
(NSString *) - sendC2CCustomMessage:to:succ:fail:
 
(NSString *) - sendGroupTextMessage:to:priority:succ:fail:
 
(NSString *) - sendGroupCustomMessage:to:priority:succ:fail:
 
(void) - addGroupListener:
 
(void) - removeGroupListener:
 
(void) - createGroup:groupID:groupName:succ:fail:
 
(void) - joinGroup:msg:succ:fail:
 
(void) - quitGroup:succ:fail:
 
(void) - dismissGroup:succ:fail:
 
(void) - setGroupListener:
 
(void) - getUsersInfo:succ:fail:
 
(void) - setSelfInfo:succ:fail:
 
(void) - callExperimentalAPI:param:succ:fail:
 

Class Methods

(V2TIMManager *) + sharedInstance
 

Protected Types

enum  V2TIMLoginStatus : NSInteger
 
enum  V2TIMLogLevel : NSInteger
 
enum  V2TIMMessagePriority : NSInteger
 
enum  V2TIMGender : NSInteger
 
enum  V2TIMFriendAllowType : NSInteger
 
enum  V2TIMGroupMemberRole : NSInteger
 
typedef void(^ V2TIMSucc) (void)
 
typedef void(^ V2TIMFail) (int code, NSString *desc)
 
typedef void(^ V2TIMCreateGroupSucc) (NSString *groupID)
 
typedef void(^ V2TIMUserFullInfoListSucc) (NSArray< V2TIMUserFullInfo * > *infoList)
 
typedef void(^ V2TIMCallExperimentalAPISucc) (NSObject *result)
 
typedef void(^ V2TIMLogListener) (V2TIMLogLevel logLevel, NSString *logContent)
 

Member Typedef Documentation

◆ V2TIMSucc

- (typedef void(^ V2TIMSucc) (void))
protected

Callback definition on success.

◆ V2TIMFail

- (typedef void(^ V2TIMFail) (int code, NSString *desc))
protected

Callback definition on fail.

◆ V2TIMCreateGroupSucc

- (typedef void(^ V2TIMCreateGroupSucc) (NSString *groupID))
protected

Callback definition on create group successfully.

◆ V2TIMUserFullInfoListSucc

- (typedef void(^ V2TIMUserFullInfoListSucc) (NSArray< V2TIMUserFullInfo * > *infoList))
protected

Callback definition on get user profiles successfully.

◆ V2TIMCallExperimentalAPISucc

- (typedef void(^ V2TIMCallExperimentalAPISucc) (NSObject *result))
protected

Callback definition for experimental api.

◆ V2TIMLogListener

- (typedef void(^ V2TIMLogListener) (V2TIMLogLevel logLevel, NSString *logContent))
protected

Log callback.

Member Enumeration Documentation

◆ V2TIMLoginStatus

- (enum V2TIMLoginStatus) :
protected

Enumeration definition of login status.

Enumerator
V2TIM_STATUS_LOGINED 

Logged in.

V2TIM_STATUS_LOGINING 

Logging in.

V2TIM_STATUS_LOGOUT 

Logged out.

◆ V2TIMLogLevel

- (enum V2TIMLogLevel) :
protected

Enumeration definition of log level.

Enumerator
V2TIM_LOG_NONE 

Do not output any SDK logs.

V2TIM_LOG_DEBUG 

Output logs at the DEBUG, INFO, WARNING, and ERROR levels.

V2TIM_LOG_INFO 

Output logs at the INFO, WARNING, and ERROR levels.

V2TIM_LOG_WARN 

Output logs at the WARNING and ERROR levels.

V2TIM_LOG_ERROR 

Output logs at the ERROR level.

◆ V2TIMMessagePriority

- (enum V2TIMMessagePriority) :
protected

Enumeration definition of message priority.

Enumerator
V2TIM_PRIORITY_DEFAULT 

Defaulted to normal priority.

V2TIM_PRIORITY_HIGH 

High priority, usually used for important messages such as gift messages.

V2TIM_PRIORITY_NORMAL 

Normal priority, usually used for common messages.

V2TIM_PRIORITY_LOW 

Low priority, usually used for like messages.

◆ V2TIMGender

- (enum V2TIMGender) :
protected

Enumeration definition of gender.

Enumerator
V2TIM_GENDER_UNKNOWN 

Unknown gender.

V2TIM_GENDER_MALE 

Male.

V2TIM_GENDER_FEMALE 

Female.

◆ V2TIMFriendAllowType

- (enum V2TIMFriendAllowType) :
protected

Enumeration definition of friend verification method.

Enumerator
V2TIM_FRIEND_ALLOW_ANY 

Automatically accept all new friend requests.

V2TIM_FRIEND_NEED_CONFIRM 

Friend request verification is required.

V2TIM_FRIEND_DENY_ANY 

Automatically reject all new friend requests.

◆ V2TIMGroupMemberRole

- (enum V2TIMGroupMemberRole) :
protected

Enumeration definition of group member role.

Enumerator
V2TIM_GROUP_MEMBER_UNDEFINED 

Undefined (this field is not obtained)

V2TIM_GROUP_MEMBER_ROLE_MEMBER 

Group member.

V2TIM_GROUP_MEMBER_ROLE_ADMIN 

Group admin.

V2TIM_GROUP_MEMBER_ROLE_SUPER 

Group owner.

Method Documentation

◆ sharedInstance()

+ (V2TIMManager*) sharedInstance

1.1 Get the V2TIMManager instance

◆ initSDK:config:()

- (BOOL) initSDK: (int)  sdkAppID
config: (V2TIMSDKConfig *)  config 

1.2 Initialize the SDK

Parameters
sdkAppIDApp ID. This field is required. You can obtain the app ID from the console.
configConfiguration information
Returns
true: successful; false: failed.

◆ addIMSDKListener:()

- (void) addIMSDKListener: (id< V2TIMSDKListener >)  listener

1.3 Add IM listener

◆ removeIMSDKListener:()

- (void) removeIMSDKListener: (id< V2TIMSDKListener >)  listener

1.4 Remove IM listener

◆ unInitSDK()

- (void) unInitSDK

1.5 Uninitialize the SDK

◆ getVersion()

- (NSString*) getVersion

1.6 Get the SDK version

Returns
Return the SDK version in string format, for example: 5.0.10

◆ getServerTime()

- (uint64_t) getServerTime

1.7 Get the server time

Returns
Server time, in seconds

◆ initSDK:config:listener:()

- (BOOL) initSDK: (int)  sdkAppID
config: (V2TIMSDKConfig *)  config
listener: (id< V2TIMSDKListener >)  listener 

Initialize the SDK.

Attention
It is deprecated and discouraged to call this function. Please call APIs ref initSDK defined in 1.2 and addIMSDKListener defined in 1.3 instead.

◆ login:userSig:succ:fail:()

- (void) login: (NSString *)  userID
userSig: (NSString *)  userSig
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

2.1 Login

userID and userSig must be set for login. For the generation of userSig, please see UserSig backend API

Attention
Note the following special logic:
  • The ticket expires before login: the callback of the login function returns the error ERR_USER_SIG_EXPIRED (6206) or ERR_SVR_ACCOUNT_USERSIG_EXPIRED (70001), and the user needs to generate a new userSig and log in again.
  • The ticket expires when the user is online: the user can receive the V2TIMListener -> onUserSigExpired callback when online, and the user also needs to generate a new userSig and log in again.
  • An online user is kicked offline: the SDK notifies the user of the logout via the V2TIMListener -> onKickedOffline callback and displays the logout notification on the UI, and the user can call login() to log in again.

◆ logout:fail:()

- (void) logout: (V2TIMSucc succ
fail: (V2TIMFail fail 

2.2 Logout

If the user logs out and switches the account, the user can log in again after the logout function calls back success or failure. Otherwise, login may fail.

◆ getLoginUser()

- (NSString *) getLoginUser

2.3 Get the login user

◆ getLoginStatus()

- (V2TIMLoginStatus) getLoginStatus

2.4 Get the login status

If the user is already in the "logged in" or "logging in" state, do not frequently call the login API to log in.

◆ addSimpleMsgListener:()

- (void) addSimpleMsgListener: (addSimpleMsgListener(listener:))  NS_SWIFT_NAME

3.1 Set the event listener for simple messages (text messages and custom messages)

Attention
For the event listener for advanced messages such as image, video, and voice messages, please see V2TIMMessageManager.addAdvancedMsgListener(V2TIMAdvancedMsgListener).

◆ removeSimpleMsgListener:()

- (void) removeSimpleMsgListener: (removeSimpleMsgListener(listener:))  NS_SWIFT_NAME

3.2 Remove the event listener for simple messages (text messages and custom messages)

◆ sendC2CTextMessage:to:succ:fail:()

- (NSString*) sendC2CTextMessage: (NSString *)  text
to: (NSString *)  userID
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

3.3 Send a one-to-one text message (up to 8 KB)

Text messages support sensitive word filtering on the cloud. For example, if a text message sent by a user contains sensitive words, the callback will return the 80001 error code.

Returns
Unique ID of the message
Attention
Messages sent via this API are pushed by default (provided that the push feature is enabled in V2TIMOfflinePushManager). If you need to customize the push (title and content), call the V2TIMMessageManager.sendMessage API.

◆ sendC2CCustomMessage:to:succ:fail:()

- (NSString*) sendC2CCustomMessage: (NSData *)  customData
to: (NSString *)  userID
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

3.4 Send a one-to-one custom (signaling) message (up to 8 KB)

A custom message is essentially a binary buffer on which you can freely organize your message format (often used to send signaling). However, custom messages do not support sensitive word filtering on the cloud.

Returns
Unique ID of the message
Attention
Messages sent via this API are not pushed by default. To push the messages, call the V2TIMMessageManager.sendMessage API.

◆ sendGroupTextMessage:to:priority:succ:fail:()

- (NSString*) sendGroupTextMessage: (NSString *)  text
to: (NSString *)  groupID
priority: (V2TIMMessagePriority priority
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

3.5 Send a group text message (up to 8 KB)

Parameters
priorityMessage priority. Though there is no way for all messages to 100% reach every user, higher-priority messages will have a higher delivery success rate.
  • HIGH :the message will be transferred with high priority on the cloud. This setting is suitable for sending important messages in the group, such as text messages sent by host.
  • NORMAL :the message will be transferred with the default priority on the cloud. This setting is suitable for sending unimportant messages in the group, such as on-screen comments sent by viewers.
Returns
Unique ID of the message
Attention
Messages sent via this API are pushed by default (provided that the push feature is enabled in V2TIMOfflinePushManager). If you need to customize the push (title and content), call the V2TIMMessageManager.sendMessage API.

◆ sendGroupCustomMessage:to:priority:succ:fail:()

- (NSString*) sendGroupCustomMessage: (NSData *)  customData
to: (NSString *)  groupID
priority: (V2TIMMessagePriority priority
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

3.6 Send a group custom (signaling) message (up to 8 KB)

Parameters
priorityMessage priority. Though there is no way for all messages to 100% reach every user, higher-priority messages will have a higher delivery success rate.
  • HIGH :the message will be transferred with high priority on the cloud. This setting is suitable for sending important messages in the group, such as mic connect invitations, competition invitation, gift-giving, and other key signaling.
  • NORMAL :the message will be transferred with the default priority on the cloud. This setting is suitable for sending unimportant signaling in the group, such as audience's like notifications.
Returns
Unique ID of the message
Attention
Messages sent via this API are not pushed by default. To push the messages, call the V2TIMMessageManager.sendMessage API.

◆ addGroupListener:()

- (void) addGroupListener: (addGroupListener(listener:))  NS_SWIFT_NAME

4.1 Add the group listener

◆ removeGroupListener:()

- (void) removeGroupListener: (removeGroupListener(listener:))  NS_SWIFT_NAME

4.2 Remove the group listener

◆ createGroup:groupID:groupName:succ:fail:()

- (void) createGroup: (NSString *)  groupType
groupID: (NSString *)  groupID
groupName: (NSString *)  groupName
succ: (V2TIMCreateGroupSucc succ
fail: (V2TIMFail fail 

4.3 Create a group

Parameters
groupTypeGroup type. The following several common group types are preset in the SDK. You can also customize desired group types in the console:
  • Work group (Work): supports up to 200 members; does not allow proactive group joining and only allows users to be invited to join the group by group members; suitable for groups like work groups created in WeChat (corresponding to Private groups in the earlier version)
  • Public group (Public): supports up to 2,000 members; allows anyone to apply to join the group, but requires group owner or admin approval for group joining; suitable for groups like interest groups managed by group owners in QQ
  • Meeting group (Meeting): supports up to 6,000 members; allows anyone to join and leave the group freely, without approval; suitable for scenarios such as video conference and online training (corresponding to ChatRoom groups in the earlier version)
  • Community : supports up to 100,000 members; allows anyone to join and leave the group freely, without approval; suitable for large community group chat scenarios such as knowledge sharing and game communication. supported only in 5.8 and later versions, need to buy Flagship Edition.
  • Audio-video group (AVChatRoom): supports an unlimited number of members; allows anyone to join and leave the group freely; features high message throughput and is suitable for use as a chat room with high-concurrency on-screen comments in live streaming scenarios
groupIDCustom group ID. "null" can be passed in. When "null" is passed in, the system automatically assigns a group ID and calls back the group ID via callback. Custom group ID of "Community" must be prefixed with "@TGS#_".
groupNameGroup name. The value cannot be "null" and can contain up to 30 bytes.
Attention
Note the following special logic:
  • Do not create groups with the same group ID under the same SDKAppID.

◆ joinGroup:msg:succ:fail:()

- (void) joinGroup: (NSString *)  groupID
msg: (NSString *)  msg
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

4.4 Join a group

Attention
Note the following special logic:
  • Work group (Work): users cannot proactively join a Work group. Only group members can call the V2TIMManager.getGroupManager().inviteUserToGroup() API to invite users to join the group.
  • Public group (Public): admin approval is required for users to join a Public group. When receiving the V2TIMGroupListener -> onReceiveJoinApplication callback, the admin needs to call the V2TIMManager.getGroupManager().getGroupApplicationList() API to handle group joining requests.
  • Other groups: users can directly join such groups.

◆ quitGroup:succ:fail:()

- (void) quitGroup: (NSString *)  groupID
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

4.5 Quit a group

Attention
For public groups (Public), meeting groups (Meeting), and audio-video groups (AVChatRoom), the group owner cannot quit the group and can only call dismissGroup to delete the group.

◆ dismissGroup:succ:fail:()

- (void) dismissGroup: (NSString *)  groupID
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

4.6 Delete a group

Attention
Note the following special logic:
  • For a work group (Work), even the group owner does not have the privilege to delete the group. To delete the group, you must have your service server to call the RESTful API Deleting a Group to delete the group.
  • For other group types, the group owner can delete the group.

◆ setGroupListener:()

- (void) setGroupListener: (id< V2TIMGroupListener >)  listener

Set the group listener

Attention
It is deprecated and discouraged to call this function. Please call APIs ref addGroupListener and removeGroupListener instead.

◆ getUsersInfo:succ:fail:()

- (void) getUsersInfo: (NSArray< NSString * > *)  userIDList
succ: (V2TIMUserFullInfoListSucc succ
fail: (V2TIMFail fail 

5.1 Get user profiles

Attention
Notes:
  • To get your own profile, pass in your user ID.
  • You are advised to specify no more than 100 user IDs in userIDList at a time. A larger number may cause the request to be rejected by the backend due to an excessively large data packet. The maximum size of a data packet supported by the backend is 1 MB.

◆ setSelfInfo:succ:fail:()

- (void) setSelfInfo: (V2TIMUserFullInfo *)  Info
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

5.2 Modify one's own user profile

◆ callExperimentalAPI:param:succ:fail:()

- (void) callExperimentalAPI: (NSString *)  api
param: (NSObject *)  param
succ: (V2TIMCallExperimentalAPISucc succ
fail: (V2TIMFail fail 

6.1 Experimental API

Parameters
apiAPI name
paramAPI parameter
Attention
This API provides some experimental features.