如何使用xmpp openfire发送输入通知

Tas*_*asZ 3 xmpp openfire objective-c ios

我正在开发聊天应用程序我想发送收件人"正在打字"当我输入消息时,任何人都知道如何使用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"];
}
Run Code Online (Sandbox Code Playgroud)

我仍然没有收到通知

Ami*_*sar 9

用于发送打字状态

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];
Run Code Online (Sandbox Code Playgroud)

在接收方

if ([message hasComposingChatState] == YES)
Run Code Online (Sandbox Code Playgroud)

检查此情况并使用正确的打字指示.

  • 看一下这个扩展类别 - XMPPMessage + XEP_0085 (2认同)