XMPPFramework - 如何获取脱机用户配置文件状态

时间:2017-06-27 13:30:43

标签: ios objective-c xmpp xmppframework

我想离线用户(朋友)状态:

我的代码在用户上线时工作正常,因此我获得了用户状态,但当他下线时container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); 提供user.primaryResource.presence.status值。

nil

用户离线后,检查XMPPUserCoreDataStorageObject *user = [[self fetchedResultsController] objectAtIndexPath:indexPath]; NSLog(@"Status: %@",user.primaryResource.presence.status); 表中是否有XMPPResourceCoreDataStorageObject,它给我零对象意味着当用户离线时删除该用户的ResourcesObject。

因此,有可能获得该用户的状态。

1 个答案:

答案 0 :(得分:0)

您检查XMPPUserCoreDataStorageObject

的源代码
- (void)updateWithPresence:(XMPPPresence *)presence streamBareJidStr:(NSString *)streamBareJidStr
{
    XMPPResourceCoreDataStorageObject *resource =
        (XMPPResourceCoreDataStorageObject *)[self resourceForJID:[presence from]];

    if ([[presence type] isEqualToString:@"unavailable"] || [presence isErrorPresence])
    {
        if (resource)
        {
            [self removeResourcesObject:resource];
            [[self managedObjectContext] deleteObject:resource];
        }
    }
    else
    {
        if (resource)
        {
            [resource updateWithPresence:presence];
        }
        else
        {
            XMPPResourceCoreDataStorageObject *newResource;
            newResource = [XMPPResourceCoreDataStorageObject insertInManagedObjectContext:[self managedObjectContext]
                                                                       withPresence:presence
                                                                   streamBareJidStr:streamBareJidStr];

            [self addResourcesObject:newResource];
        }
    }

    [self recalculatePrimaryResource];
}

如果离线,您可以看到resource将被删除。

对于我自己,我将user.primaryResource?.presence?.type() == "available"检查为online,将其他情况检查为offline。 (假设用户是您从db获得的XMPPUserCoreDataStorageObject