我正在为我当前的项目使用robbiehanson / XMPPFramework。 如何使用XMPPFramework获取消息输入状态?有XEP-184协议,但现在已弃用。 需要帮助来获取iOS中的撰写状态。 问候, 铢
答案 0 :(得分:7)
首先导入:
#import "XMPPMessage+XEP_0085.h"
然后根据您的目的添加以下方法。
.....构成
- (void)sendComposingChatToUser:(XMPPJID*)jid {
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message];
[xmppMessage addComposingChatState];
[xmppStream sendElement:message];
}
有效.....
- (void)sendActiveChatToUser:(XMPPJID*)jid {
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message];
[xmppMessage addActiveChatState];
[xmppStream sendElement:message];
}
无效...
- (void)sendInactiveChatToUser:(XMPPJID*)jid {
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message];
[xmppMessage addInactiveChatState];
[xmppStream sendElement:message];
}
...飘
- (void)sendExitChatToUser:(XMPPJID*)jid {
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message];
[xmppMessage addGoneChatState];
[xmppStream sendElement:xmppMessage];
}
...暂停
- (void)sendPausedChatToUser:(XMPPJID*)jid {
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message];
[xmppMessage addPausedChatState];
[xmppStream sendElement:message];
}
然后您应该在appdelgate中编写以下代码。 (didReceiveMessage)方法。
例如:
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message{
if ([message isChatMessageWithBody]){
}
else{
if([message elementForName:@"composing"] != nil){
} else if ([message elementForName:@"paused"] != nil) {
} else if ([message elementForName:@"gone"] || [message elementForName:@"inactive"] ) {
}
}
答案 1 :(得分:2)
&#34;联系人最常用的协议是输入&#34;通知是XEP-0085: Chat State Notifications。如那里更详细地描述的那样,给联系人的第一条消息应该包含一个&#34; active&#34; state元素(<body/>
元素旁边):
<active xmlns='http://jabber.org/protocol/chatstates'/>
如果联系人以聊天状态响应,则客户端可以继续使用其他状态,例如&#34;撰写&#34;:
<composing xmlns='http://jabber.org/protocol/chatstates'/>
或&#34;暂停&#34; (用户输入了文字,但没有主动输入):
<paused xmlns='http://jabber.org/protocol/chatstates'/>
或&#34;不活跃&#34;,最后&#34;去了&#34;当用户通过关闭聊天窗口或类似内容结束对话时。