【问题标题】:how to send typing notification using xmpp openfire如何使用 xmpp openfire 发送打字通知
【发布时间】:2014-07-06 23:34:02
【问题描述】:

我正在开发聊天应用程序,我想在我输入消息时向收件人发送“正在输入”,有没有人知道如何使用 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"];
}

我仍然没有收到通知

【问题讨论】:

    标签: ios objective-c xmpp openfire


    【解决方案1】:

    用于发送打字状态

    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)
    

    检查此条件并将其与您的打字指示正确使用。

    【讨论】:

    • 看看这个扩展类——XMPPMessage+XEP_0085
    • 但更大的挑战是如何从您设置的标签中删除“打字...”
    • 我们在哪里可以检查这个状态?
    • @jaskiratjd 在接收消息的委托方法
    猜你喜欢
    • 2013-05-28
    • 2019-02-08
    • 2016-12-20
    • 1970-01-01
    • 2013-04-12
    • 2014-07-11
    • 2011-10-01
    • 2017-06-01
    相关资源
    最近更新 更多