差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
im:other:integrationcases:snapchat [2018/09/25 10:39] jk |
im:other:integrationcases:snapchat [2023/05/15 09:46] victorli [iOS示例] |
||
---|---|---|---|
行 43: | 行 43: | ||
NSDictionary *ext = @{FIRE_FLAG:@YES}; | NSDictionary *ext = @{FIRE_FLAG:@YES}; | ||
NSString *currentUsername = [EMClient sharedClient].currentUsername; // 当前登录环信id | NSString *currentUsername = [EMClient sharedClient].currentUsername; // 当前登录环信id | ||
- | EMMessage *msg = [[EMMessage alloc] initWithConversationID:toUsername | + | EMChatMessage *msg = [[EMChatMessage alloc] initWithConversationID:toUsername |
from:currentUsername | from:currentUsername | ||
to:toUsername | to:toUsername | ||
行 52: | 行 52: | ||
</code> | </code> | ||
+ | === web/小程序示例 === | ||
+ | <code> | ||
+ | let id = conn.getUniqueId(); // 生成本地消息id | ||
+ | let msg = new WebIM.message('txt', id); // 创建文本消息 | ||
+ | msg.set({ | ||
+ | msg: '这是一条阅后即焚消息', // 消息内容 | ||
+ | to: 'username', // 接收消息对象(用户id) | ||
+ | chatType: 'singleChat', // 设置为单聊 | ||
+ | ext: {fire: true}, // 消息扩展,标记为阅后即焚 | ||
+ | success: function (id, serverMsgId) {}, | ||
+ | fail: function(e){} | ||
+ | }); | ||
+ | conn.send(msg.body); | ||
+ | </code> | ||
===== 接收阅后即焚消息,查看后发送回执并删除本地消息 ===== | ===== 接收阅后即焚消息,查看后发送回执并删除本地消息 ===== | ||
行 100: | 行 114: | ||
// 当用户已经读取过消息后,删除消息并发送已读回执 | // 当用户已经读取过消息后,删除消息并发送已读回执 | ||
- | - (void)fireMessageAndSendAck:(EMMessage *)message { | + | - (void)fireMessageAndSendAck:(EMChatMessage *)message { |
// 发送已读回执 | // 发送已读回执 | ||
[EMClient.sharedClient.chatManager sendMessageReadAck:message completion:nil]; | [EMClient.sharedClient.chatManager sendMessageReadAck:message completion:nil]; | ||
行 109: | 行 123: | ||
</code> | </code> | ||
+ | === web/小程序示例 === | ||
+ | <code> | ||
+ | /** | ||
+ | * 新消息回调 | ||
+ | */ | ||
+ | onTextMessage(message){ | ||
+ | // 判断是否为阅后即焚消息 | ||
+ | if(message.ext.fire){ | ||
+ | // update ui | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // 当用户已经读取过消息后,发送已读回执并删除本地消息 | ||
+ | var msgId = message.id; // 需要发送已读回执的消息id | ||
+ | var msg = new WebIM.message('read', conn.getUniqueId()); // 已读回执消息 | ||
+ | msg.set({ | ||
+ | id: msgId, | ||
+ | to: message.from | ||
+ | }); | ||
+ | conn.send(msg.body); | ||
+ | |||
+ | </code> | ||
===== 消息发送方收到回执,判断需要焚毁,删除本地消息 ===== | ===== 消息发送方收到回执,判断需要焚毁,删除本地消息 ===== | ||
行 139: | 行 175: | ||
// 收到已读回执 | // 收到已读回执 | ||
- (void)messagesDidRead:(NSArray *)aMessages { | - (void)messagesDidRead:(NSArray *)aMessages { | ||
- | for (EMMessage *msg in aMessages) { | + | for (EMChatMessage *msg in aMessages) { |
if ([msg.ext[FIRE_FLAG] boolValue]) { | if ([msg.ext[FIRE_FLAG] boolValue]) { | ||
EMConversation *con = [EMClient.sharedClient.chatManager getConversation:msg.from type:EMConversationTypeChat createIfNotExist:YES]; // 消息所在会话 | EMConversation *con = [EMClient.sharedClient.chatManager getConversation:msg.from type:EMConversationTypeChat createIfNotExist:YES]; // 消息所在会话 | ||
行 149: | 行 185: | ||
</code> | </code> | ||
+ | === web/小程序示例 === | ||
+ | |||
+ | <code> | ||
+ | /** | ||
+ | * 收到消息已读回执 | ||
+ | */ | ||
+ | onReadMessage(message){ | ||
+ | // 判断这个已读回执是发送的那条阅后即焚消息的回执 | ||
+ | if(message.id === fireMessage.id){ | ||
+ | // 删除此条消息 | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
---- | ---- | ||
<WRAP group> | <WRAP group> | ||
行 156: | 行 205: | ||
<WRAP half column> | <WRAP half column> | ||
- | 下一页:[[im:other:integrationcases:revokemessages|消息回撤]] | + | 下一页:[[im:other:integrationcases:revokemessages|消息撤回]] |
</WRAP> | </WRAP> | ||
</WRAP> | </WRAP> | ||