【iOS XMPP】使用XMPPFramewok(四):收发消息
来源:互联网 发布:skypixel软件 编辑:程序博客网 时间:2024/06/05 03:47
接收消息
通过实现
- (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
- mybatis 映射文件中$ # 的区别
- 【iOS XMPP】使用XMPPFramewok(三):好友状态
- 对比现在各种主流语言的优劣
- 设计模式之反思(一)
- 通过loosejar清理应用中冗余的jar包
- 【iOS XMPP】使用XMPPFramewok(四):收发消息
- 内部函数和外部函数
- 【iOS XMPP】使用XMPPFramewok(五):好友列表
- LeetCode | First Missing Positive(第一个缺失的正整数)
- QT学习7:程序打包发布
- leetcode 刷题之路 75 Plus One
- 黑马程序员_JAVA基础_IO流(一)
- fedora下字体安装
- 编程珠玑中一些算法