如何在安卓设备中从Openfire检索聊天记录。

3

我有一个聊天应用程序,想要检索两个用户之间的聊天历史记录,我已经有了一个用于检索聊天消息的标签,它是...

    <iq type='get' id='pk1'>
<list xmlns='urn:xmpp:archive'
with='shrey27@sys1-pc'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>30</max>
</set>
</list>
</iq>

现在,我的问题是如何将这个段落发送到服务器,以便我可以获得响应。我已安装消息归档插件,消息存储得非常完美。有什么建议吗?谢谢!

1个回答

4
NSXMLElement *iQ = [NSXMLElement elementWithName:@"iq"];
[iQ addAttributeWithName:@"type" stringValue:@"get"];
[iQ addAttributeWithName:@"id" stringValue:@"987654321"];

NSXMLElement *list = [NSXMLElement elementWithName:@"list"];
[list addAttributeWithName:@"xmlns" stringValue:@"urn:xmpp:archive"];
[list addAttributeWithName:@"with" stringValue:@"bhushan@mydomain.com"];



NSXMLElement *set = [NSXMLElement elementWithName:@"set"];
[set addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/rsm"];

NSXMLElement *max = [NSXMLElement elementWithName:@"max"];
[max addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/rsm"];
max.stringValue = @"30";

[set addChild:max];

[list addChild:set];
[iQ addChild:list];
[[[self appDelegate] xmppStream] sendElement:iQ];

你可以这样调用。希望能对你有所帮助 :)

1
嗨Karun,感谢您提供这个有用的代码片段。当我在我的应用程序中执行代码时,服务器会以错误代码503的形式给出service-unavailable的响应。您能否建议我可能犯了什么错误?响应是通过委托方法- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq返回的。谢谢。 - Yogi
@Yogi 我也遇到了同样的问题。你找到解决方案了吗? - Hassan Aftab
如果我在Swift 3中实现某个东西,会出现501错误,这个特性还未实现。 - Mad Burea
你还需要在Openfire服务器中安装Openfire插件,但你可能无法得到完全符合你要求的内容。http://stackoverflow.com/questions/42084375/while-fetching-chat-history-i-am-not-getting-both-user-history-from-openfire - Mad Burea

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接