gpt4 book ai didi

ios - XMPPFramework - 如何接收名册的存在信息以及名册列表?

转载 作者:行者123 更新时间:2023-12-01 17:25:32 26 4
gpt4 key购买 nike

需要帮助以获取有关好友的存在信息的信息。

我正在调用“fetchRoster”函数,但是我正在获取名册列表而不是存在信息。

我也尝试显式调用存在信息。但是在我的 iOS 应用程序中没有调用 didRecievePresence 委托(delegate)。

问候,
克哈特

最佳答案

From Robbiehanson's XMPPFramework - RootViewController class:

  • 获取您的名单
    - (NSFetchedResultsController *)fetchedResultsController
    {
    if (fetchedResultsController == nil)
    {
    NSManagedObjectContext *moc = [[self appDelegate] managedObjectContext_roster];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"XMPPUserCoreDataStorageObject"
    inManagedObjectContext:moc];

    NSSortDescriptor *sd1 = [[NSSortDescriptor alloc] initWithKey:@"sectionNum" ascending:YES];
    NSSortDescriptor *sd2 = [[NSSortDescriptor alloc] initWithKey:@"displayName" ascending:YES];

    NSArray *sortDescriptors = [NSArray arrayWithObjects:sd1, sd2, nil];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:entity];
    [fetchRequest setSortDescriptors:sortDescriptors];
    [fetchRequest setFetchBatchSize:10];

    fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
    managedObjectContext:moc
    sectionNameKeyPath:@"sectionNum"
    cacheName:nil];
    [fetchedResultsController setDelegate:self];


    NSError *error = nil;
    if (![fetchedResultsController performFetch:&error])
    {
    DDLogError(@"Error performing fetch: %@", error);
    }
    }

    return fetchedResultsController;
    }
  • 每当服务器中记录用户存在的更改时重新加载您的表
    - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
    {
    [[self tableView] reloadData];
    }
  • 显示头像(头像)
    - (void)configurePhotoForCell:(UITableViewCell *)cell user:(XMPPUserCoreDataStorageObject *)user
    {
    // Our xmppRosterStorage will cache photos as they arrive from the xmppvCardAvatarModule.
    // We only need to ask the avatar module for a photo, if the roster doesn't have it.

    if (user.photo != nil)
    {
    cell.imageView.image = user.photo;
    }
    else
    {
    NSData *photoData = [[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid];

    if (photoData != nil)
    cell.imageView.image = [UIImage imageWithData:photoData];
    else
    cell.imageView.image = [UIImage imageNamed:@"defaultPerson"];
    }
    }
  • 将表格分为两部分 - 可用/离线
    - (NSString *)tableView:(UITableView *)sender titleForHeaderInSection:(NSInteger)sectionIndex
    {
    NSArray *sections = [[self fetchedResultsController] sections];

    if (sectionIndex < [sections count])
    {
    id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:sectionIndex];

    int section = [sectionInfo.name intValue];
    switch (section)
    {
    case 0 : return @"Available";
    case 1 : return @"Away";
    default : return @"Offline";
    }
    }

    return @"";
    }
  • 使用用户的显示名称显示您的整个花名册
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
    reuseIdentifier:CellIdentifier];
    }

    XMPPUserCoreDataStorageObject *user = [[self fetchedResultsController] objectAtIndexPath:indexPath];

    cell.textLabel.text = user.displayName;
    [self configurePhotoForCell:cell user:user];

    return cell;
    }

  • 这包含在您下载的 XMPPFramework 中。尝试一下。我所说的这 5 点可能是您所需要的。

    关于ios - XMPPFramework - 如何接收名册的存在信息以及名册列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24209804/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com