1,注释的地方 如果放出来,会 出现发送两遍消息的错觉,
2,并且消息的 id有一模一样的,如果 刚好用这个做 id的话 会出现 主键约束,而 离线消息只能插入一条的情况,
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
TTLog(@"receive message -----------------%@",message);
IMMessageInfo *iMessageInfo = [[IMRootManagershareManager]xmppMessageToChatMessage:message stateFlag:RECEIVE_SUCCESS];
[[DBcontrolsharedDBControl] saveIMMessage:iMessageInfo];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:message, IM_MESSAGE_BODY, nil];
[[NSNotificationCenterdefaultCenter] postNotificationName:IM_MESSAGE_RECEIVEobject:selfuserInfo:userInfo];
if([UIApplicationsharedApplication].applicationState == UIApplicationStateBackground){
[selfpushLocalNotification:message];
}
// if([message hasReceiptRequest]){
// XMPPMessage *responseMessage = [message generateReceiptResponse];
// NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
// [body setStringValue:@"r"];
// [responseMessage addChild:body];
// [xmppStream sendElement:responseMessage];
// }
if ([message isChatMessageWithBody]) {
NSString *messageID = [ChatVoiceRecorderVC getCurrentTimeString];
[message addAttributeWithName:@"id" stringValue:messageID];
TTLog(@" message with id-----------------%@",message);
}
}