我正在向我的jabber服务器发送请求以获取我的联系人列表。
现在我的问题是didReceiveIQ
方法被称为多次。
那么我怎么能识别出当调用didReciveIQ时,它应该是我的联系人列表。
答案 0 :(得分:2)
从jabber服务器获取联系人列表
-(void)fetchRosterListWithUserId:(NSString *)userId // yourID
{
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];
XMPPIQ *iq = [XMPPIQ iq];
[iq addAttributeWithName:@"id" stringValue:FETCH_ROSTER_DISCO_ID];
[iq addAttributeWithName:@"to" stringValue:userId];
[iq addAttributeWithName:@"type" stringValue:@"get"];
[iq addChild:query];
[_xmppStream sendElement:iq];
您可以在
中获取回复 - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
// You can identify the response by using @"id"
if([[iq attributeStringValueForName:@"id"] isEqualToString:FETCH_ROSTER_DISCO_ID])
{
//Extract contact list from response here
}
}