如何使用目标c中的xmpp向特定组发送消息

时间:2017-05-31 06:52:11

标签: ios objective-c xmpp xmppframework

我的项目中有4个小组,而我发送的消息是我使用过的代码。我在我的项目中使用xmpp

但它没有将消息发送给小组。

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

  self.messageField.text = @"";
}

那么如何使用xmpp

向特定群组发送消息

2 个答案:

答案 0 :(得分:0)

您可以使用groupJID(例如groupName @ domainName)以这种方式发送短信,例如

**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];

答案 1 :(得分:0)

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

  self.messageField.text = @"";