iphone xmppframework如何列出我的特定域的所有在线用户

时间:2011-07-26 20:42:48

标签: iphone xmppframework

我正在使用xmppframework for iPhone。我想知道如何查看我的特定域的所有可用用户?

由于

1 个答案:

答案 0 :(得分:5)

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {

    NSString *presenceType = [presence type]; // online/offline
    NSString *myUsername = [[sender myJID] user];
    NSString *presenceFromUser = [[presence from] user];


    if (![presenceFromUser isEqualToString:myUsername]) {

        if ([presenceType isEqualToString:@"available"]) {
            [_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, @"gmail.com"]];

        } else if ([presenceType isEqualToString:@"unavailable"]) {

            [_chatDelegate buddyWentOffline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, @"gmail.com"]];

        }

    }
}

将此方法用于AppDelegate文件。

使用newBuddyOnline方法创建@protocol。

在你想要显示列表的地方,你只需使用这些方法,..

- (void)newBuddyOnline:(NSString *)buddyName {

    [onlineBuddies addObject:buddyName];
    [self.TableView reloadData];
}

- (void)buddyWentOffline:(NSString *)buddyName {
    [onlineBuddies removeObject:buddyName];
    [self.TableView reloadData];
}