【iOS XMPP】使用XMPPFramewok(四):收发消息
来源:互联网 发布:淘宝返利的软件哪个好 编辑:程序博客网 时间:2024/05/26 05:52
收发消息
接收消息
通过实现
- (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];}
0 0
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- ios 使用XMPPFramewok:收发消息
- 【iOS XMPP】使用XMPPFramewok(二):用户登录
- 【iOS XMPP】使用XMPPFramewok(三):好友状态
- 【iOS XMPP】使用XMPPFramewok(五):好友列表
- 【iOS XMPP】使用XMPPFramewok(二):用户登录
- 【iOS XMPP】使用XMPPFramewok(三):好友状态
- 【iOS XMPP】使用XMPPFramewok(五):好友列表
- 【iOS XMPP】使用XMPPFramewok(二):用户登录
- 【iOS XMPP】使用XMPPFramewok(三):好友状态
- 【iOS XMPP】使用XMPPFramewok(五):好友列表
- 【iOS XMPP】使用XMPPFramewok(一):添加XMPPFramework
- SSH通信协议浅析
- Android实现程序前后台切换效果
- sublime 使用(备忘)
- MySQL存储引擎简介
- elasticsearch文档-analysis
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 10gocm->session3->数据备份与恢复
- Dalsa - 图像处理软件 Dalsa视觉检测 请加群304023601
- vim简明教程
- 【iOS XMPP】使用XMPPFramewok(五):好友列表
- 前端开发常用js框架收集
- android中SQLite数据库中用insert同时插入多条记录的方法和效率比较
- 一个功能齐全的IOS音乐播放器应用源码
- listview不刷新问题