码迷,mamicode.com
首页 > 移动开发 > 详细

XMPP iOS客户端开发(二) 通信

时间:2014-12-23 17:27:53      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:xmpp   ios   

发送消息:

- (void) sendMessage:(NSString *) message toUser:(NSString *) user
{
    NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
    body.stringValue = message;
    NSXMLElement *msg = [NSXMLElement elementWithName:@"message"];
    [msg addAttributeWithName:@"type" stringValue:@"chat"];
    NSString *to = [NSString stringWithFormat:@"%@@shenqi",user];
    [msg addAttributeWithName:@"to" stringValue:to];
    [msg addChild:body];
    [_xmppStream sendElement:msg];
    
}

收到消息:

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
    NSString *messageBody =  [message elementsForName:@"body"][0];
    NSLog(@"messageBody = %@",messageBody);
    
}


XMPP iOS客户端开发(二) 通信

标签:xmpp   ios   

原文地址:http://blog.csdn.net/qqmcy/article/details/42104019

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!