如何在robbiehanson XMPPFramework中发送消息

时间:2014-03-20 20:15:34

标签: xcode xmpp xmppframework

我可以很好地接收来自其他客户的消息,但我不确定发送消息是否热门。我已经看过一些代码,但我不确定代码应该在哪里。在XMPPStream.m中?如果是的话,在哪里?

1 个答案:

答案 0 :(得分:1)

将以下代码添加到RootviewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

   XMPPUserCoreDataStorageObject * currentUser = [[self fetchedResultsController] objectAtIndexPath:indexPath];


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

    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:currentUser.jidStr];
    [message addChild:body];

    [[[self appDelegate] xmppStream] sendElement:message];

}