IOS Chat application using XMPP Protocol (ejabberd) Room chat issue

瘦欲@ 提交于 2019-12-08 15:29:32

Following code snippet worked for me.. Try it for your code... I have sent uuid of my device as child while sending message and checked the same uuid at the time of incoming message :

-(void)sendMessageWithBody:(NSString *)messageBody
{
    if ([messageBody length] == 0) return;

    NSXMLElement *body = [NSXMLElement elementWithName:@"body" stringValue:messageBody];

    XMPPMessage *message = [XMPPMessage message];
    [message addChild:body];

    NSString *uuidString=[UIDevice currentDevice].identifierForVendor.UUIDString;

    NSXMLElement *myMsgLogic=[NSXMLElement elementWithName:@"myMsgLogic" stringValue:uuidString];
    [message addChild:myMsgLogic];

    [self sendMessage:message];
}

-(void)xmppRoom:(XMPPRoom *)sender didReceiveMessage:(XMPPMessage *)message fromOccupant:(XMPPJID *)occupantJID;
{
    [self handleIncomingMessage:message room:xmppRoom];
}

-(void)handleIncomingMessage:(XMPPMessage *)message room:(XMPPRoom *)room
{
    NSString *uuidString=[UIDevice currentDevice].identifierForVendor.UUIDString;

    NSString *messageLogic= [[message elementsForName:@"myMsgLogic"].firstObject stringValue];

    if ([uuidString isEqualToString:messageLogic]) {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"handleIncomingMessage" message:[message body] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
    }
}

I have the same chat application using xmpp ejabbered. I was also facing the same problem. In my case on xmpp server they have set offline message storage to 100. If in offline mode the message limit crossed 100 then from 101th message I will get bounce back that message. So as a solution we changed the offline message limit to 500.

{mod_offline_odbc, [
 {user_max_messages, 500}
]}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!