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) - subscribeUserInfo:succ:fail:
 
(void) - unsubscribeUserInfo:succ:fail:
 
(void) - getUserStatus:succ:fail:
 
(void) - setSelfStatus:succ:fail:
 
(void) - subscribeUserStatus:succ:fail:
 
(void) - unsubscribeUserStatus:succ:fail:
 
(void) - callExperimentalAPI:param:succ:fail:
 

Class Methods

(V2TIMManager *) + sharedInstance
 

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.

◆ V2TIMUserStatusListSucc

- (typedef void(^ V2TIMUserStatusListSucc) (NSArray< V2TIMUserStatus * > *result))
protected

Callback definition on get user status list successfully.

◆ 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 

Medium priority (default)

V2TIM_PRIORITY_HIGH 

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

V2TIM_PRIORITY_NORMAL 

Medium 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.

◆ V2TIMUserStatusType

- (enum V2TIMUserStatusType) :
protected

Enumeration definition of user status type.

Enumerator
V2TIM_USER_STATUS_UNKNOWN 

Unknown status.

V2TIM_USER_STATUS_ONLINE 

Online status.

V2TIM_USER_STATUS_OFFLINE 

Offline status.

V2TIM_USER_STATUS_UNLOGINED 

Unlogined status (such as logout or registering)

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 a Chat listener

◆ removeIMSDKListener:()

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

1.4 Remove a Chat 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
UTC timestamp, 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 Log in

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 V2TIMListener -> onUserSigExpired callback may also be triggered when the user is online. In this case, generate a new userSig and log in again.
  • An online user is kicked offline: this will be notified by the V2TIMListener -> onKickedOffline callback. After receiving this callback, you can notify the user via the UI and call login() to log the user in again.

◆ logout:fail:()

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

2.2 Log out

In the case of switching accounts, after the user logs out, they can log in again only after a logout callback is received (whether the logout succeeds or fails).

◆ getLoginUser()

- (NSString *) getLoginUser

2.3 Get the logged in 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 12 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 12 KB)

A custom message is essentially a binary buffer which allows you to customize your message format (often used to send signaling). 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 12 KB)

Parameters
priorityMessage priority. There is no guarantee that each message will reach all users, but higher-priority messages will have a higher delivery success rate.
  • HIGH :the message will be transferred with a high priority on the cloud. This setting is suitable for sending important messages in a group, such as text messages sent by the host.
  • NORMAL :the message will be transferred with the default priority on the cloud. This setting is suitable for sending less important messages in a 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 12 KB)

Parameters
priorityMessage priority. There is no guarantee that each message will reach all users, but higher-priority messages will have a higher delivery success rate.
  • HIGH :the message will be transferred with a high priority on the cloud. This setting is suitable for sending important messages in a 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 less important signaling in a group, such as likes given by the audience.
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 group types are preset in the SDK. You can also customize group types in the console:
  • Work group (Work): supports up to 200 members; allows join by invitation only; suitable for work groups like those in WeCom (corresponding to Private groups in earlier versions)
  • 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 earlier versions)
  • 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 Premium 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. "nil" can be passed in. When "nil" is passed in, the system automatically assigns a group ID and returns it via a callback. Custom group ID of "Community" must be prefixed with "@TGS#_".
groupNameGroup name. The value cannot be "nil". The maximum length is 100 bytes, using UTF-8 encoding, and 1 Chinese character occupies 3 bytes.
Attention
Note the following special logic:
  • Do not create groups with the same group ID under the same SDKAppID.
  • Audio-video group (AVChatRoom): After the process is restarted or the user is logged in again, for them to continue to receive messages from the same Audio-video group, please call joinGroup to join the group again.

◆ 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.
  • Audio-video group (AVChatRoom): After the process is restarted or the user is logged in again, for them to continue to receive messages from the same Audio-video group, please call joinGroup to join the group again.

◆ 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 call the RESTful API Deleting a 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
  • 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

◆ subscribeUserInfo:succ:fail:()

- (void) subscribeUserInfo: (NSArray *)  userIDList
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

5.3 Subscribe to user profiles (supported only in Chat Premium 7.4 and later versions)

Parameters
userIDList
Attention
  • This API is used to subscribe to stranger profiles, and after successfully subscribing, you will receive profile change notifications via the onUserInfoChanged callback.
  • A maximum of 200 subscriptions are allowed. When the limit is exceeded, the earliest subscriptions will be automatically eliminated.
  • You don't need to subscribe to your own or your friends' profiles. By default, any changes to your own and your friends' profiles will be notified via the onSelfInfoUpdated and onFriendInfoChange callback.

◆ unsubscribeUserInfo:succ:fail:()

- (void) unsubscribeUserInfo: (NSArray *)  userIDList
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

5.4 Unsubscribe user profile (supported only in Chat Premium 7.4 and later versions)

Parameters
userIDListIdentifiers for users whose profiles you want to unsubscribe from. If userIDList is empty, all subscriptions will be canceled.

◆ getUserStatus:succ:fail:()

- (void) getUserStatus: (NSArray *)  userIDList
succ: (V2TIMUserStatusListSucc succ
fail: (V2TIMFail fail 

5.5 Get user status information (supported only in Chat Premium 6.3 and later versions)

Parameters
userIDListList of identifier of the users whose information is to be obtained.
Attention
  • To get your own custom status, pass in your userID.
  • An error will be returned only if query fails for all specified users.

◆ setSelfStatus:succ:fail:()

- (void) setSelfStatus: (V2TIMUserStatus *)  status
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

5.6 Set your own user status (supported only in 6.3 and later versions)

Attention
You can only set your custom status (the customStatus field of V2TIMUserStatus) using this API.

◆ subscribeUserStatus:succ:fail:()

- (void) subscribeUserStatus: (NSArray *)  userIDList
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

5.7 Subscribe to user status (supported only in Chat Premium 6.3 and later versions)

Parameters
userIDListIdentifiers for users whose status you want to subscribe to.
Attention
  • You will receive status change notifications via the onUserStatusChanged callback after successfully subscribing to user status.
  • To subscribe to the status of your friends, instead of calling this API, please configure it in the console.
  • You cannot use this API to subscribe to your own status. Instead, you can receive notifications about change of your own custom status via the onUserStatusChanged callback.
  • A maximum of 200 subscriptions are allowed. When the limit is exceeded, earlier subscriptions will be automatically canceled.

◆ unsubscribeUserStatus:succ:fail:()

- (void) unsubscribeUserStatus: (NSArray *)  userIDList
succ: (V2TIMSucc succ
fail: (V2TIMFail fail 

5.8 Unsubscribe from user status (supported only in Chat Premium 6.3 and later versions)

Parameters
userIDListIdentifiers for users whose status you want to unsubscribe from. If useridList is empty, all subscriptions will be canceled.

◆ 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.