zoukankan      html  css  js  c++  java
  • xmpp这一段蛋疼的 坑,

    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);

     

          

        }

       

    }

  • 相关阅读:
    [LeetCode]24. Search Insert Position插入位置
    [LeetCode]23. Set Matrix Zeroes矩阵清零
    [LeetCode]22. 3Sum Closest最近三者之和
    [LeetCode]21. 3Sum三者之和
    [LeetCode]20. Unique Paths II唯一路径
    [LeetCode]19. Unique Paths唯一路径
    [LeetCode]18. Contains Duplicate II重复检测
    [LeetCode]17. Majority Element主元素
    第13章建造者模式
    第15章抽象工厂模式
  • 原文地址:https://www.cnblogs.com/guligei/p/3645138.html
Copyright © 2011-2022 走看看