问题
I have a chat app in which I want to retrieve chat history between two users, I have a stanza for retrieving chat messages and that is...
<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>
now, my problem is how can I fire this stanza to the server so that I can get the response.I have installed the message archiving plugin and messages are getting stored perfectly.any suggestions would be beneficial... thanks in advance!!!
回答1:
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];
You can call like this. Hope this helps :)
来源:https://stackoverflow.com/questions/21657530/how-to-retrieve-chat-history-from-open-fire-in-android