简体   繁体   中英

how to send a message to particular group using xmpp in objective c

I'm having the 4 groups in my project, while I'm sending the message I have used this code. I'm using xmpp in my project.

But it is not sending the message to the group.

  NSString *messageString = self.messageField.text;
  if([messageString length] > 0) {  
    [self.xmppManager.xmppRoom sendMessageWithBody:messageString];
  }

  self.messageField.text = @"";
}

So how do I send message to particular group using xmpp

You can send text message to this way with your groupJID (ex. groupName@domainName ) for example

**Swift 3.0**

   let completeMessage = DDXMLElement.element(withName: "message") as! DDXMLElement        

   completeMessage.addAttribute(withName: "id", stringValue: messageID!)
   completeMessage.addAttribute(withName: "type", stringValue: 
          "groupchat")

   completeMessage.addAttribute(withName: "to", stringValue: 
       recieverJID)

   let body = DDXMLElement.element(withName: "body") as! DDXMLElement

   body.stringValue = trimmedMessage
   completeMessage.addChild(body)
   sender.send(completeMessage)

**Objective C**

   NSXMLElement *message = [NSXMLElement elementWithName:@"message"];

   [message addAttributeWithName:@"id" stringValue: messageID];
   [message addAttributeWithName:@"type" stringValue:@"groupchat"];
   [message addAttributeWithName:@"to" stringValue:recieverJID];

   NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
   [body setStringValue:messageStr];

   [message addChild:body];
   [sender sendElement:message];
NSString *messageString = self.messageField.text;
  if([messageString length] > 0) {  
    [self.xmppManager.xmppRoom sendMessageWithBody:messageString];
  }

  self.messageField.text = @"";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM