关于极光SDK消息重复的问题

下面的接口由极光SDK提供:

/*!
 * @abstract 同步分页获取最新的消息
 *
 * @param offset 开始的位置。nil 表示从最初开始。
 * @param limit 获取的数量。nil 表示不限。
 *
 * @return 返回消息列表(数组)。数组成员的类型是 JMSGMessage*
 *
 * @discussion 排序规则是:最新
 *
 * 参数举例:
 *
 * - offset = nil, limit = nil,表示获取全部。相当于 allMessages。
 * - offset = nil, limit = 100,表示从最新开始取 100 条记录。
 * - offset = 100, limit = nil,表示从最新第 100 条开始,获取余下所有记录。
 */
- (NSArray JMSG_GENERIC(__kindof JMSGMessage *) *)messageArrayFromNewestWithOffset:(NSNumber *JMSG_NULLABLE)offset
                                                                             limit:(NSNumber *JMSG_NULLABLE)limit;
在项目中进行调用时的截图

以下内容为上面截图中,messaegArray中保存的内容,注意:消息发生了重复的情况;

<__NSArrayM 0x13f4748d0>(
 - [ARRAY - msgId:msgId_1473509068255972, serverMessageId:116387500, otherSide:69117813, isReceived:1, contentType:文本消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10183381","target_name":"人脉通广州交流群","from_type":"user","from_id":"69117813","from_name":"梁锦锟","from_platform":"i","create_time":1473506849708,"msg_type":"text","msg_body":{"text":"多,只是都潜水去了"},"from_appkey":"ce6e8aee881ae9689975e3b8"}, content:{
  "text" : "多,只是都潜水去了"
}, fromAppKey:ce6e8aee881ae9689975e3b8, targetAppKey:],
 - [ARRAY - msgId:msgId_1473509082984970, serverMessageId:116387500, otherSide:69117813, isReceived:1, contentType:文本消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10183381","target_name":"人脉通广州交流群","from_type":"user","from_id":"69117813","from_name":"梁锦锟","from_platform":"i","create_time":1473506849708,"msg_type":"text","msg_body":{"text":"多,只是都潜水去了"},"from_appkey":"ce6e8aee881ae9689975e3b8"}, content:{
  "text" : "多,只是都潜水去了"
}, fromAppKey:ce6e8aee881ae9689975e3b8, targetAppKey:],
 - [ARRAY - msgId:msgId_1473509045563820, serverMessageId:116261981, otherSide:60018153, isReceived:1, contentType:文本消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10183381","target_name":"人脉通广州交流群","from_type":"user","from_id":"60018153","from_name":"吴生生","from_platform":"i","create_time":1473496050433,"msg_type":"text","msg_body":{"text":"好象人不多"},"from_appkey":"ce6e8aee881ae9689975e3b8"}, content:{
  "text" : "好象人不多"
}, fromAppKey:ce6e8aee881ae9689975e3b8, targetAppKey:],
 - [ARRAY - msgId:msgId_1473509060277678, serverMessageId:116261981, otherSide:60018153, isReceived:1, contentType:文本消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10183381","target_name":"人脉通广州交流群","from_type":"user","from_id":"60018153","from_name":"吴生生","from_platform":"i","create_time":1473496050433,"msg_type":"text","msg_body":{"text":"好象人不多"},"from_appkey":"ce6e8aee881ae9689975e3b8"}, content:{
  "text" : "好象人不多"
}, fromAppKey:ce6e8aee881ae9689975e3b8, targetAppKey:],
 - [ARRAY - msgId:msgId_1473509082140174, serverMessageId:116260688, otherSide:60018153, isReceived:1, contentType:文本消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10183381","target_name":"人脉通广州交流群","from_type":"user","from_id":"60018153","from_name":"吴生生","from_platform":"i","create_time":1473496021410,"msg_type":"text","msg_body":{"text":"在"},"from_appkey":"ce6e8aee881ae9689975e3b8"}, content:{
  "text" : "在"
}, fromAppKey:ce6e8aee881ae9689975e3b8, targetAppKey:],
 - [ARRAY - msgId:msgId_1473479835203404, serverMessageId:115923727, otherSide:67437495, isReceived:1, contentType:文本消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10183381","target_name":"人脉通广州交流群","from_type":"user","from_id":"67437495","from_name":"罗文统","from_platform":"i","create_time":1473464578486,"msg_type":"text","msg_body":{"text":"有人在吗"},"from_appkey":"ce6e8aee881ae9689975e3b8"}, content:{
  "text" : "有人在吗"
}, fromAppKey:ce6e8aee881ae9689975e3b8, targetAppKey:]
)

问题分析:

这个问题很难重现,有时候重现时,重复现象非常严重。
根据本次重现并捕获的结果来看,虽然消息内容重复,但是确实是两个不同的JMSGMessage对象实例,0x13e9c1aa0,0x13f1b20f0; 再仔细看,会发现这两个实例虽然不同、msgId不同,但是serverMessageId 是相同的,因此可以认定,这两条为同一条消息;


再看一个例子:

下面的例子中,serverMessageId为 ,这类消息的contentType为:事件通知消息,如果没有serverMessageId的话,在项目APP中,就无法做消息去重操作时的唯一性判断了。

 - [ARRAY - msgId:msgId_1473509120198886, serverMessageId:, otherSide:10206763, isReceived:0, contentType:事件通知消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10206763","target_name":"微商直销交流十群","from_type":"user","from_id":"57717435","from_name":"张先生","from_platform":"i","create_time":1473509120000,"msg_type":"event_notification","msg_body":{"toUidList":["17316843"],"eventType":10,"fromUid":0,"cTime":1473508977,"eventDesc":"eventID->62576905,fromUid->0,type->10,eventDescription->(null),gid->10206763,rid->62576905","eventId":62576905,"gid":"10206763"},"from_appkey":null}, content:{
  "toUidList" : [
    "17316843"
  ],
  "eventType" : 10,
  "fromUid" : 0,
  "cTime" : 1473508977,
  "eventDesc" : "eventID->62576905,fromUid->0,type->10,eventDescription->(null),gid->10206763,rid->62576905",
  "eventId" : 62576905,
  "gid" : "10206763"
}, fromAppKey:, targetAppKey:],
 - [ARRAY - msgId:msgId_1473509119631641, serverMessageId:, otherSide:10206763, isReceived:0, contentType:事件通知消息, status:消息接收成功, messageJson:{"version":1,"target_type":"group","target_id":"10206763","target_name":"微商直销交流十群","from_type":"user","from_id":"57717435","from_name":"张先生","from_platform":"i","create_time":1473509119000,"msg_type":"event_notification","msg_body":{"toUidList":["17107554"],"eventType":10,"fromUid":0,"cTime":1473508953,"eventDesc":"eventID->62576493,fromUid->0,type->10,eventDescription->(null),gid->10206763,rid->62576493","eventId":62576493,"gid":"10206763"},"from_appkey":null}, content:{
  "toUidList" : [
    "17107554"
  ],
  "eventType" : 10,
  "fromUid" : 0,
  "cTime" : 1473508953,
  "eventDesc" : "eventID->62576493,fromUid->0,type->10,eventDescription->(null),gid->10206763,rid->62576493",
  "eventId" : 62576493,
  "gid" : "10206763"
}, fromAppKey:, targetAppKey:]

你可能感兴趣的:(关于极光SDK消息重复的问题)