标签:blog http io ar os 使用 sp for strong
转自:http://www.cnblogs.com/dyingbleed/archive/2013/05/16/3075105.html
收发消息
接收消息
通过实现
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message;
方法
当接收到 <message /> 标签的内容时,XMPPFramework 框架回调该方法
根据 XMPP 协议,消息体的内容存储在标签 <body /> 内
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message { NSString *messageBody = [[message elementForName:@"body"] stringValue]; }
发送消息
发送消息,我们需要根据 XMPP 协议,将数据放到 <message /> 标签内,例如:
<message type="chat" to="xiaoming@example.com">
<body>Hello World!<body />
<message />
- (void)sendMessage:(NSString *) message toUser:(NSString *) user { NSXMLElement *body = [NSXMLElement elementWithName:@"body"]; [body setStringValue:message]; NSXMLElement *message = [NSXMLElement elementWithName:@"message"]; [message addAttributeWithName:@"type" stringValue:@"chat"]; NSString *to = [NSString stringWithFormat:@"%@@example.com", user]; [message addAttributeWithName:@"to" stringValue:to]; [message addChild:body]; [self.xmppStream sendElement:message]; }
【iOS XMPP】使用XMPPFramewok(四):收发消息
标签:blog http io ar os 使用 sp for strong
原文地址:http://www.cnblogs.com/wangpei/p/4126550.html