如何使用XMPP openfire发送打字通知



我正在开发聊天应用程序,当我输入消息时,我想发送收件人"正在打字",有人知道如何使用XMPP框架和开火作为服务器来做到这一点吗?

下面是我的代码

-(void)sendChatStateNotification: (NSString *)strState
{
     NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
     NSXMLElement *chatStatus=[NSXMLElement elementWithName:strState xmlns:xmlns_chatstates];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:chatWithUser];
    [message addChild:chatStatus];
}
-(void)textViewDidChange:(UITextView *)textView
{
    [self sendChatStateNotification:@"composing"];
}

我仍然没有收到通知

发送输入状态

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue: toID];
NSXMLElement *composing = [NSXMLElement elementWithName:@"composing"];
[composing addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/chatstates"];
[message addChild:composing];
[xmppStream sendElement:message];

接收侧

if ([message hasComposingChatState] == YES)

检查此条件并根据您的打字指示正确使用

最新更新