XMPp MultiUserChat Group (MUC) Does Not Stable

I created an Xmpp Chat application in which I implemented individual and group chat. Chat itself is working fine. The problem is in group chat. I created a group with 2-3 members, the chat again works fine, but when I kill the application and restart it, I do not receive group messages from any of the groups that I created. while I am connected to the XMPP server and reconnecting to any group, then I get messages. My problem is that I have to join the groups again every time after I completely kill the application.

Please let me know how I can receive messages or automatically join a group when I open the application from a killed state.

+4
source share
5 answers

You need to send the presence to the server XMPPafter starting the application or exiting the background. therefore, the server XMPPunderstands that the corresponding one is groupready to handle the event.

Edit : You can send a presence using the following code.

- (void)goOnline {


    NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
    NSXMLElement *show = [NSXMLElement elementWithName:@"show"
                                           stringValue:@"dnd"];
    NSXMLElement *status = [NSXMLElement elementWithName:@"status" stringValue:@"available"];
    NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" stringValue:@"24"];

    [presence addChild:show];
    [presence addChild:status];
    [presence addChild:priority];

    [_xmppStream sendElement:presence];

    [self createOrJoinRoom];

}
- (void)createOrJoinRoom {
    if ([appDelegate.xmppStream isConnected]) {

        NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:@"XMPPUserId"];

        NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
        [presence addAttributeWithName:@"from" stringValue:[[appDelegate.xmppStream myJID]full]];
        [presence addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@@%@/%@", @"newone", GroupChatRoomName,myJID]];
        NSXMLElement *xelement = [NSXMLElement elementWithName:@"x" xmlns:XMPPMUCNamespace];
        [presence addChild:xelement];
        [appDelegate.xmppStream sendElement:presence];
    }

}

May this help you.

+1
source

You need to join all of your previous join / join groups. Because in iOS, if you kill your application, you left your created or merged groups.

Therefore, every time in this section of code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

you need to join your group again.

Below is a demo code:

XMPPRoomHybridStorage *xmppRoomStorage1 = [XMPPRoomHybridStorage sharedInstance];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage1 jid:RoomName];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:appDelegate.Obj_xmppManager.xmppStream];
NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"1"];
[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user history:nil];
+1
source

"", -

  • ( )? , ? ( "" "" ).
    - , , , - , - , , ?

  • , , , , , , - (openfire, ejabbered, prosody )? ?

  • , , , , \ ? ?

0

, google , .

, , , , , , .

, , , , .

NSString *roomJID = [NSString stringWithFormat:@"%@@conference.yourHostName", roomJid];
XMPPJID *jid = [XMPPJID jidWithString:roomJID];

_xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomCoreDataStorage jid:jid dispatchQueue:dispatch_get_main_queue()];
[_xmppRoom activate:stream];
[_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[_xmppRoom joinRoomUsingNickname:stream.myJID.bare history:nil];

, .

0

By default, MUCRoom will send some history to the newly connected user, the number is determined by the configuration in mod_muc: history_size:. Or you need to explicitly request a certain amount of history when sending Presence, doc :

<presence
    from='hag66@shakespeare.lit/pda'
    id='n13mt3l'
    to='coven@chat.shakespeare.lit/thirdwitch'>
  <x xmlns='http://jabber.org/protocol/muc'>
    <history maxstanzas='20'/>
  </x>
</presence>
0
source

Source: https://habr.com/ru/post/1589174/


All Articles