XMPPFramework - 如何识别' didReceiveIQ'响应是否是用户的联系人列表?

时间:2014-07-04 04:46:35

标签: ios xmpp xmppframework

我正在向我的jabber服务器发送请求以获取我的联系人列表。

现在我的问题是didReceiveIQ方法被称为多次。

那么我怎么能识别出当调用didReciveIQ时,它应该是我的联系人列表。

1 个答案:

答案 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
        }
    }