发送消息:
- (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); }
原文地址:http://blog.csdn.net/qqmcy/article/details/42104019