NIMSDK-iOS
载入中...
搜索中...
未找到
NIMChatManagerProtocol.h
浏览该文件的文档.
1//
2// NIMChatManagerProtocol.h
3// NIMLib
4//
5// Created by Netease.
6// Copyright (c) 2015 Netease. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10
11@class NIMMessage;
12@class NIMSession;
17
18NS_ASSUME_NONNULL_BEGIN
19
20/**
21 * P2P 发送已读回执 Block
22 *
23 * @param error 错误信息,如果成功,error 为 nil
24 */
25typedef void(^NIMSendMessageReceiptBlock)(NSError * __nullable error);
26
27/**
28 * Team 发送已读回执 Block
29 *
30 * @param error 错误信息,如果成功,error 为 nil
31 * @param failedReceipts 失败的回执
32 */
33typedef void(^NIMSendTeamMessageReceiptsBlock)(NSError * __nullable error,NSArray<NIMMessageReceipt *> * __nullable failedReceipts);
34
35/**
36 * 撤回消息Block
37 *
38 * @param error 错误信息,如果成功,error 为 nil
39 */
40typedef void(^NIMRevokeMessageBlock)(NSError * __nullable error);
41
42/**
43 * 查询群组消息回执详情Block
44 *
45 * @param error 错误,如果成功则error为nil
46 * @param detail 已读回执详情
47 */
48typedef void(^NIMQueryReceiptDetailBlock)(NSError * __nullable error,NIMTeamMessageReceiptDetail * __nullable detail);
49
50
51/**
52 * 操作完成回调
53 *
54 * @param error 错误,如果成功则error为nil
55 */
56typedef void(^NIMChatManagerBlock)(NSError * __nullable error);
57
58
59/**
60 * 聊天委托
61 */
62@protocol NIMChatManagerDelegate <NSObject>
63
64@optional
65/**
66 * 即将发送消息回调
67 * @discussion 因为发消息之前可能会有个准备过程,所以需要在收到这个回调时才将消息加入到 Datasource 中
68 * @param message 当前发送的消息
69 */
70- (void)willSendMessage:(NIMMessage *)message;
71
72
73/**
74 * 上传资源文件成功的回调
75 * @discussion 对于需要上传资源的消息(图片,视频,音频等),SDK 将在上传资源成功后通过这个接口进行回调,上层可以在收到该回调后进行推送信息的重新配置 (APNS payload)
76 * @param urlString 当前消息资源获得的 url 地址
77 * @param message 当前发送的消息
78 */
79- (void)uploadAttachmentSuccess:(NSString *)urlString
80 forMessage:(NIMMessage *)message;
81
82/**
83 * 发送消息进度回调
84 *
85 * @param message 当前发送的消息
86 * @param progress 进度
87 */
88- (void)sendMessage:(NIMMessage *)message
89 progress:(float)progress;
90
91
92/**
93 * 发送消息完成回调
94 *
95 * @param message 当前发送的消息
96 * @param error 失败原因,如果发送成功则error为nil
97 */
98- (void)sendMessage:(NIMMessage *)message
99 didCompleteWithError:(nullable NSError *)error;
100
101
102/**
103 * 收到消息回调
104 *
105 * @param messages 消息列表,内部为NIMMessage
106 */
107- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages;
108
109/**
110 * 收到消息回执
111 *
112 * @param receipts 消息回执数组
113 * @discussion 当上层收到此消息时所有的存储和 model 层业务都已经更新,只需要更新 UI 即可。
114 */
115- (void)onRecvMessageReceipts:(NSArray<NIMMessageReceipt *> *)receipts;
116
117
118/**
119 * 收到消息被撤回的通知
120 *
121 * @param notification 被撤回的消息信息
122 * @discusssion 云信在收到消息撤回后,会先从本地数据库中找到对应消息并进行删除,之后通知上层消息已删除
123 */
124- (void)onRecvRevokeMessageNotification:(NIMRevokeMessageNotification *)notification;
125
126
127/**
128 * 收取消息附件回调
129 * @param message 当前收取的消息
130 * @param progress 进度
131 * @discussion 附件包括:图片,视频的缩略图,语音文件
132 */
133- (void)fetchMessageAttachment:(NIMMessage *)message
134 progress:(float)progress;
135
136
137/**
138 * 收取消息附件完成回调
139 *
140 * @param message 当前收取的消息
141 * @param error 错误返回,如果收取成功,error为nil
142 */
143- (void)fetchMessageAttachment:(NIMMessage *)message
144 didCompleteWithError:(nullable NSError *)error;
145
146@end
147
148
149/**
150 * 聊天协议
151 */
152@protocol NIMChatManager <NSObject>
153
154/**
155 * 发送消息
156 *
157 * @param message 消息
158 * @param session 接受方
159 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
160 *
161 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
162 */
163- (BOOL)sendMessage:(NIMMessage *)message
164 toSession:(NIMSession *)session
165 error:(NSError * __nullable *)error;
166
167
168/**
169 * 异步发送消息
170 *
171 * @param message 消息
172 * @param session 接收方
173 * @param completion 发送完成后的回调,这里的回调完成只表示当前这个函数调用完成,需要后续的回调才能判断消息是否已经发送至服务器
174 */
175- (void)sendMessage:(NIMMessage *)message
176 toSession:(NIMSession *)session
177 completion:(__nullable NIMChatManagerBlock)completion;
178
179
180/**
181 * 取消正在发送的消息
182 *
183 * @param message 目标消息
184 * @return 是否调用成功
185 */
186- (BOOL)cancelSendingMessage:(NIMMessage *)message;
187
188
189/**
190 * 重发消息
191 *
192 * @param message 重发消息
193 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
194 *
195 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
196 */
197- (BOOL)resendMessage:(NIMMessage *)message
198 error:(NSError * __nullable *)error;
199
200
201/**
202 * 生成转发消息
203 * 得到转发消息后,开发者需要自己再调用sendForwardMessage:toSession:error: 进行发送, 和 直接调用forwardMessage:toSession:error:效果一样,但是这样可以得到转发消息的进度方法回调和是否转发成功方法回调
204 *
205 * @param message 要转发的消息
206 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
207 *
208 * @return 生成的需要转发的消息
209 */
210- (NIMMessage *)makeForwardMessageFromMessage:(NIMMessage *)message
211 error:(NSError *__autoreleasing _Nullable * _Nullable)error;
212
213/**
214 * 发送生成的转发消息
215 *
216 * @param message 转发消息
217 * @param session 接受方
218 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
219 *
220 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
221 */
222- (BOOL)sendForwardMessage:(NIMMessage *)message
223 toSession:(NIMSession *)session
224 error:(NSError * __nullable *)error;
225
226/**
227 * 转发消息
228 *
229 * @param message 消息
230 * @param session 接收方
231 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
232 *
233 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
234 */
235- (BOOL)forwardMessage:(NIMMessage *)message
236 toSession:(NIMSession *)session
237 error:(NSError * __nullable *)error;
238
239
240/**
241 * 发送已读回执 (P2P)
242 *
243 * @param receipt 已读回执
244 * @param completion 完成回调
245 * @discussion 此接口仅适用于 P2P 消息,群消息已读回执使用 sendTeamMessageReceipts:completion 如果已有比当前已读回执时间戳更大的已读回执已确认,则接口返回成功。
246 */
247- (void)sendMessageReceipt:(NIMMessageReceipt *)receipt
248 completion:(nullable NIMSendMessageReceiptBlock)completion;
249
250
251/**
252 * 发送已读回执 (Team 批量接口)
253 *
254 * @param receipts 已读回执 receipts count 最多不超过50个
255 * @param completion 完成回调
256 * @discussion 此接口仅适用于 Team 消息。
257 */
258- (void)sendTeamMessageReceipts:(NSArray<NIMMessageReceipt *> *)receipts
259 completion:(nullable NIMSendTeamMessageReceiptsBlock)completion;
260
261
262/**
263 * 刷新群组消息已读、未读数量
264 *
265 * @param messages 要查询的消息集合
266 * @discussion 消息已读变化后,会通过 NIMChatManager 的代理 onRecvMessageReceipts: 回调给上层
267 * 刷新的消息必须为群组消息
268 */
269- (void)refreshTeamMessageReceipts:(NSArray<NIMMessage *> *)messages;
270
271
272/**
273 * 查询群组消息回执详情
274 *
275 * @param message 要查询的消息
276 * @param completion 完成后的回调
277 * @discussion 详情包括已读人数的 id 列表和未读人数的 id 列表
278 * 查询详情对象不会跟着回执人数变化而变化,如果要获取最新的详情,必须再次调用此接口
279 *
280 */
281- (void)queryMessageReceiptDetail:(NIMMessage *)message
282 completion:(NIMQueryReceiptDetailBlock)completion;
283/**
284 * 查询群组消息指定用户的回执详情
285 *
286 * @param message 待查询的消息
287 * @param accountSet 指定的用户的账号组成的NSSet
288 * @return 该消息的已读、未读账号列表
289 */
290- (void)queryMessageReceiptDetail:(NIMMessage *)message
291 accountSet:(NSSet *)accountSet
292 completion:(NIMQueryReceiptDetailBlock)completion;
293
294/**
295* 从本地数据库查询单条群组消息已读、未读账号列表
296* 注意!!!:这里获取的数据通常比离线前的列表信息更陈旧
297*
298* @param message 待查询的消息
299* @return 该消息的已读、未读账号列表
300*/
301- (nullable NIMTeamMessageReceiptDetail *)localMessageReceiptDetail:(NIMMessage *)message;
302
303/**
304* 从本地数据库查询单条群组消息在指定用户中的已读、未读账号列表(同步接口)
305* 注意!!!:这里获取的数据通常比离线前的列表信息更陈旧
306*
307* @param message 待查询的消息
308* @param accountSet 指定的用户的账号组成的NSSet
309* @return 该消息的已读、未读账号列表
310*/
311- (nullable NIMTeamMessageReceiptDetail *)localMessageReceiptDetail:(NIMMessage *)message
312 accountSet:(NSSet *)accountSet;
313
314/**
315 * 撤回消息,不含推送信息
316 *
317 * @param message 需要被撤回的消息
318 * @param completion 完成回调
319 * @discussion 消息计入未读数
320 */
321- (void)revokeMessage:(NIMMessage *)message
322 completion:(nullable NIMRevokeMessageBlock)completion;
323
324/**
325 * 撤回消息
326 *
327 * @param message 需要被撤回的消息
328 * @param apnsContent 云信推送内容,长度限制500字
329 * @param apnsPayload 云信推送payload信息,长度限制 2K
330 * @param should 是否计入未读数
331 * @param completion 完成回调
332 */
333- (void)revokeMessage:(NIMMessage *)message
334 apnsContent:(nullable NSString *)apnsContent
335 apnsPayload:(nullable NSDictionary *)apnsPayload
336 shouldBeCounted:(BOOL)should
337 completion:(nullable NIMRevokeMessageBlock)completion;
338
339/**
340* 撤回消息
341*
342* @param message 需要被撤回的消息
343* @param option 撤回的配置选项
344* @param completion 完成回调
345* @discussion 消息计入未读数
346*/
347- (void)revokeMessage:(NIMMessage *)message
348 option:(NIMRevokeMessageOption *)option
349 completion:(nullable NIMRevokeMessageBlock)completion;
350
351
352/**
353 * 收取消息附件
354 *
355 * @param message 需要收取附件的消息
356 * @param error 错误
357 *
358 * @return 是否调用成功
359 * @discussion 附件包括:图片消息的图片缩略图,视频消息的视频缩略图,音频消息的音频文件,文件消息的文件以及自定义消息中的自定义文件
360 * 个人和群组消息 SDK 会在收到该消息时自动调用本接口,自动下载除 "文件消息的文件" 外的所有附件内容
361 *
362 */
363- (BOOL)fetchMessageAttachment:(NIMMessage *)message
364 error:(NSError * __nullable *)error;
365
366
367
368/**
369 * 取消收取消息附件
370 *
371 * @param message 需要取消收取附件的消息
372 *
373 * @discussion 附件包括:图片消息的图片缩略图,视频消息的视频缩略图,音频消息的音频文件,文件消息的文件以及自定义消息中的自定义文件
374 * 个人和群组消息。SDK 不会触发任何下载回调
375 */
376- (void)cancelFetchingMessageAttachment:(NIMMessage *)message;
377
378/**
379 * 消息是否正在传输 (发送/接受附件)
380 *
381 * @param message 消息
382 *
383 * @return 是否正在传输
384 */
385- (BOOL)messageInTransport:(NIMMessage *)message;
386
387/**
388 * 传输消息的进度 (发送/接受附件)
389 *
390 * @param message 消息
391 *
392 * @return 正在传输的消息进度,如果消息不在传输,则返回0
393 */
394- (float)messageTransportProgress:(NIMMessage *)message;
395
396/**
397 * 添加聊天委托
398 *
399 * @param delegate 聊天委托
400 */
401- (void)addDelegate:(id<NIMChatManagerDelegate>)delegate;
402
403/**
404 * 移除聊天委托
405 *
406 * @param delegate 聊天委托
407 */
408- (void)removeDelegate:(id<NIMChatManagerDelegate>)delegate;
409@end
410
411NS_ASSUME_NONNULL_END
void(^ NIMSendTeamMessageReceiptsBlock)(NSError *__nullable error, NSArray< NIMMessageReceipt * > *__nullable failedReceipts)
Definition: NIMChatManagerProtocol.h:33
void(^ NIMChatManagerBlock)(NSError *__nullable error)
Definition: NIMChatManagerProtocol.h:56
void(^ NIMRevokeMessageBlock)(NSError *__nullable error)
Definition: NIMChatManagerProtocol.h:40
NS_ASSUME_NONNULL_BEGIN typedef void(^ NIMSendMessageReceiptBlock)(NSError *__nullable error)
void(^ NIMQueryReceiptDetailBlock)(NSError *__nullable error, NIMTeamMessageReceiptDetail *__nullable detail)
Definition: NIMChatManagerProtocol.h:48
Definition: NIMMessage.h:90
Definition: NIMMessageReceipt.h:21
Definition: NIMRevokeMessageNotification.h:45
Definition: NIMRevokeMessageOption.h:14
Definition: NIMSession.h:49
Definition: NIMTeamMessageReceiptDetail.h:19