I am using robbiehanson/XMPPFramework for my current project. How to get the message typing status using XMPPFramework? There XEP- 184 protocol but those are deprecated right now . Need assistance here for getting composing status in iOS . Regards, Bhat
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The most commonly used protocol for "contact is typing" notifications is XEP-0085: Chat State Notifications. As described in more detail there, the first message to a contact should contain an "active" state element (next to the <body/>
element):
<active xmlns='http://jabber.org/protocol/chatstates'/>
If the contact responds with a chat state, the client can go ahead and use other states, such as "composing":
<composing xmlns='http://jabber.org/protocol/chatstates'/>
or "paused" (the user has entered text, but isn't actively typing):
<paused xmlns='http://jabber.org/protocol/chatstates'/>
or "inactive", and finally "gone" when the user ends the conversation by closing the chat window or similar.
回答2:
First you import:
#import "XMPPMessage+XEP_0085.h"
and then you add the following methods according to your purpose.
composing.....
- (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];
}
Active.....
- (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];
}
Inactive...
- (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];
}
Gone...
- (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];
}
Paused...
- (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];
}
then You should write following code in appdelgate. (didReceiveMessage) method.
Ex:
- (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"] ) {
}
}