Skip to content

Commit e35a594

Browse files
committed
发布 5.7.1435 版本
1 parent 87facf0 commit e35a594

File tree

1 file changed

+205
-0
lines changed

1 file changed

+205
-0
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
- (void)onRecvNewMessage:(V2TIMMessage *)msg
2+
{
3+
// 文本消息
4+
if (msg.elemType == V2TIM_ELEM_TYPE_TEXT) {
5+
V2TIMTextElem *textElem = msg.textElem;
6+
NSString *text = textElem.text;
7+
NSLog(@"文本信息 : %@", text);
8+
}
9+
// 自定义消息
10+
else if (msg.elemType == V2TIM_ELEM_TYPE_CUSTOM) {
11+
V2TIMCustomElem *customElem = msg.customElem;
12+
NSData *customData = customElem.data;
13+
NSLog(@"自定义信息 : %@",customData);
14+
}
15+
// 图片消息
16+
else if (msg.elemType == V2TIM_ELEM_TYPE_IMAGE) {
17+
V2TIMImageElem *imageElem = msg.imageElem;
18+
// 一个图片消息会包含三种格式大小的图片,分别为原图、大图、微缩图(SDK 会在发送图片消息的时候自动生成微缩图、大图,客户不需要关心)
19+
// 大图:是将原图等比压缩,压缩后宽、高中较小的一个等于720像素。
20+
// 缩略图:是将原图等比压缩,压缩后宽、高中较小的一个等于198像素。
21+
NSArray<V2TIMImage *> *imageList = imageElem.imageList;
22+
for (V2TIMImage *timImage in imageList) {
23+
// 图片 ID,内部标识,可用于外部缓存 key
24+
NSString *uuid = timImage.uuid;
25+
// 图片类型
26+
V2TIMImageType type = timImage.type;
27+
// 图片大小(字节)
28+
int size = timImage.size;
29+
// 图片宽度
30+
int width = timImage.width;
31+
// 图片高度
32+
int height = timImage.height;
33+
// 设置图片下载路径 imagePath,这里可以用 uuid 作为标识,避免重复下载
34+
NSString *imagePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testImage%@",timImage.uuid]];
35+
// 判断 imagePath 下有没有已经下载过的图片文件
36+
if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
37+
// 下载图片
38+
[timImage downloadImage:imagePath progress:^(NSInteger curSize, NSInteger totalSize) {
39+
// 下载进度
40+
NSLog(@"下载图片进度:curSize:%lu,totalSize:%lu",curSize,totalSize);
41+
} succ:^{
42+
// 下载成功
43+
NSLog(@"下载图片完成");
44+
} fail:^(int code, NSString *msg) {
45+
// 下载失败
46+
NSLog(@"下载图片失败:code:%d,msg:%@",code,msg);
47+
}];
48+
} else {
49+
// 图片已存在
50+
}
51+
NSLog(@"图片信息:uuid:%@,type:%ld,size:%d,width:%d,height:%d",uuid,(long)type,size,width,height);
52+
}
53+
}
54+
// 语音消息
55+
else if (msg.elemType == V2TIM_ELEM_TYPE_SOUND) {
56+
V2TIMSoundElem *soundElem = msg.soundElem;
57+
// 语音 ID,内部标识,可用于外部缓存 key
58+
NSString *uuid = soundElem.uuid;
59+
// 语音文件大小
60+
int dataSize = soundElem.dataSize;
61+
// 语音时长
62+
int duration = soundElem.duration;
63+
// 设置语音文件路径 soundPath,这里可以用 uuid 作为标识,避免重复下载
64+
NSString *soundPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testSound%@",uuid]];
65+
// 判断 soundPath 下有没有已经下载过的语音文件
66+
if (![[NSFileManager defaultManager] fileExistsAtPath:soundPath]) {
67+
// 下载语音
68+
[soundElem downloadSound:soundPath progress:^(NSInteger curSize, NSInteger totalSize) {
69+
// 下载进度
70+
NSLog(@"下载语音进度:curSize:%lu,totalSize:%lu",curSize,totalSize);
71+
} succ:^{
72+
// 下载成功
73+
NSLog(@"下载语音完成");
74+
} fail:^(int code, NSString *msg) {
75+
// 下载失败
76+
NSLog(@"下载语音失败:code:%d,msg:%@",code,msg);
77+
}];
78+
} else {
79+
// 语音已存在
80+
}
81+
NSLog(@"语音信息:uuid:%@,dataSize:%d,duration:%d,soundPath:%@",uuid,dataSize,duration,soundPath);
82+
}
83+
// 视频消息
84+
else if (msg.elemType == V2TIM_ELEM_TYPE_VIDEO) {
85+
V2TIMVideoElem *videoElem = msg.videoElem;
86+
// 视频截图 ID,内部标识,可用于外部缓存 key
87+
NSString *snapshotUUID = videoElem.snapshotUUID;
88+
// 视频截图文件大小
89+
int snapshotSize = videoElem.snapshotSize;
90+
// 视频截图宽
91+
int snapshotWidth = videoElem.snapshotWidth;
92+
// 视频截图高
93+
int snapshotHeight = videoElem.snapshotHeight;
94+
// 视频 ID,内部标识,可用于外部缓存 key
95+
NSString *videoUUID = videoElem.videoUUID;
96+
// 视频文件大小
97+
int videoSize = videoElem.videoSize;
98+
// 视频时长
99+
int duration = videoElem.duration;
100+
// 设置视频截图文件路径,这里可以用 uuid 作为标识,避免重复下载
101+
NSString *snapshotPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testVideoSnapshot%@",snapshotUUID]];
102+
if (![[NSFileManager defaultManager] fileExistsAtPath:snapshotPath]) {
103+
// 下载视频截图
104+
[videoElem downloadSnapshot:snapshotPath progress:^(NSInteger curSize, NSInteger totalSize) {
105+
// 下载进度
106+
NSLog(@"%@", [NSString stringWithFormat:@"下载视频截图进度:curSize:%lu,totalSize:%lu",curSize,totalSize]);
107+
} succ:^{
108+
// 下载成功
109+
NSLog(@"下载视频截图完成");
110+
} fail:^(int code, NSString *msg) {
111+
// 下载失败
112+
NSLog(@"%@", [NSString stringWithFormat:@"下载视频截图失败:code:%d,msg:%@",code,msg]);
113+
}];
114+
} else {
115+
// 视频截图已存在
116+
}
117+
NSLog(@"视频截图信息:snapshotUUID:%@,snapshotSize:%d,snapshotWidth:%d,snapshotWidth:%d,snapshotPath:%@",snapshotUUID,snapshotSize,snapshotWidth,snapshotHeight,snapshotPath);
118+
119+
// 设置视频文件路径,这里可以用 uuid 作为标识,避免重复下载
120+
NSString *videoPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testVideo%@",videoUUID]];
121+
if (![[NSFileManager defaultManager] fileExistsAtPath:videoPath]) {
122+
// 下载视频
123+
[videoElem downloadVideo:videoPath progress:^(NSInteger curSize, NSInteger totalSize) {
124+
// 下载进度
125+
NSLog(@"%@", [NSString stringWithFormat:@"下载视频进度:curSize:%lu,totalSize:%lu",curSize,totalSize]);
126+
} succ:^{
127+
// 下载成功
128+
NSLog(@"下载视频完成");
129+
} fail:^(int code, NSString *msg) {
130+
// 下载失败
131+
NSLog(@"%@", [NSString stringWithFormat:@"下载视频失败:code:%d,msg:%@",code,msg]);
132+
}];
133+
} else {
134+
// 视频已存在
135+
}
136+
NSLog(@"视频信息:videoUUID:%@,videoSize:%d,duration:%d,videoPath:%@",videoUUID,videoSize,duration,videoPath);
137+
}
138+
// 文件消息
139+
else if (msg.elemType == V2TIM_ELEM_TYPE_FILE) {
140+
V2TIMFileElem *fileElem = msg.fileElem;
141+
// 文件 ID,内部标识,可用于外部缓存 key
142+
NSString *uuid = fileElem.uuid;
143+
// 文件名称
144+
NSString *filename = fileElem.filename;
145+
// 文件大小
146+
int fileSize = fileElem.fileSize;
147+
// 设置文件路径,这里可以用 uuid 作为标识,避免重复下载
148+
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testFile%@",uuid]];
149+
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
150+
// 下载文件
151+
[fileElem downloadFile:filePath progress:^(NSInteger curSize, NSInteger totalSize) {
152+
// 下载进度
153+
NSLog(@"%@", [NSString stringWithFormat:@"下载文件进度:curSize:%lu,totalSize:%lu",curSize,totalSize]);
154+
} succ:^{
155+
// 下载成功
156+
NSLog(@"下载文件完成");
157+
} fail:^(int code, NSString *msg) {
158+
// 下载失败
159+
NSLog(@"%@", [NSString stringWithFormat:@"下载文件失败:code:%d,msg:%@",code,msg]);
160+
}];
161+
} else {
162+
// 文件已存在
163+
}
164+
NSLog(@"文件信息:uuid:%@,filename:%@,fileSize:%d,filePath:%@",uuid,filename,fileSize,filePath);
165+
}
166+
// 地理位置消息
167+
else if (msg.elemType == V2TIM_ELEM_TYPE_LOCATION) {
168+
V2TIMLocationElem *locationElem = msg.locationElem;
169+
// 地理位置信息描述
170+
NSString *desc = locationElem.desc;
171+
// 经度
172+
double longitude = locationElem.longitude;
173+
// 纬度
174+
double latitude = locationElem.latitude;
175+
NSLog(@"地理位置信息:desc:%@,longitude:%f,latitude:%f",desc,longitude,latitude);
176+
}
177+
// 表情消息
178+
else if (msg.elemType == V2TIM_ELEM_TYPE_FACE) {
179+
V2TIMFaceElem *faceElem = msg.faceElem;
180+
// 表情所在的位置
181+
int index = faceElem.index;
182+
// 表情自定义数据
183+
NSData *data = faceElem.data;
184+
NSLog(@"表情信息:index:%d,data:%@",index,data);
185+
}
186+
// 群 tips 消息
187+
else if (msg.elemType == V2TIM_ELEM_TYPE_GROUP_TIPS) {
188+
V2TIMGroupTipsElem *tipsElem = msg.groupTipsElem;
189+
// 所属群组
190+
NSString *groupID = tipsElem.groupID;
191+
// 群Tips类型
192+
V2TIMGroupTipsType type = tipsElem.type;
193+
// 操作人资料
194+
V2TIMGroupMemberInfo * opMember = tipsElem.opMember;
195+
// 被操作人资料
196+
NSArray<V2TIMGroupMemberInfo *> * memberList = tipsElem.memberList;
197+
// 群信息变更详情
198+
NSArray<V2TIMGroupChangeInfo *> * groupChangeInfoList = tipsElem.groupChangeInfoList;
199+
// 群成员变更信息
200+
NSArray<V2TIMGroupMemberChangeInfo *> * memberChangeInfoList = tipsElem.memberChangeInfoList;
201+
// 当前群在线人数
202+
uint32_t memberCount = tipsElem.memberCount;
203+
NSLog(@"群 tips 信息:groupID:%@,type:%ld,opMember:%@,memberList:%@,groupChangeInfoList:%@,memberChangeInfoList:%@,memberCount:%u",groupID,(long)type,opMember,memberList,groupChangeInfoList,memberChangeInfoList,memberCount);
204+
}
205+
}

0 commit comments

Comments
 (0)