如何在iOS中获得openfire/xmpp中所有在线用户的列表?
我正在获得用户在线/离线状态。这样,如果我需要检查,我每次都必须发送请求以获取状态如何在iOS中获得openfire/xmpp中所有在线用户的列表?,ios,xmpp,openfire,xmppframework,Ios,Xmpp,Openfire,Xmppframework,我正在获得用户在线/离线状态。这样,如果我需要检查,我每次都必须发送请求以获取状态 如何检查多个用户或仅在线用户?使用服务器上的在线用户插件。通过这种方式,您可以通过http获得在线用户 以下是链接: 我已实现NSFetchedResultsControllerDelegate。我越来越 “SectionNum”中的联机用户列表=0。无论用户何时离开 脱机/联机控制器的委托方法称为.update 桌面视图 //NSFetchedResultsController*fetchedResultsCo
如何检查多个用户或仅在线用户?使用服务器上的在线用户插件。通过这种方式,您可以通过http获得在线用户 以下是链接: 我已实现NSFetchedResultsControllerDelegate。我越来越 “SectionNum”中的联机用户列表=0。无论用户何时离开 脱机/联机控制器的委托方法称为.update 桌面视图 //NSFetchedResultsController*fetchedResultsController//实例变量
in viewWillAppear
//xmpp user array
self.xmppUserArray=[[[self fetchedResultsController] fetchedObjects] mutableCopy];
for (int i=0; i<[[self xmppUserArray] count]; i++) {
if ([[[[self xmppUserArray] objectAtIndex:i] valueForKey:@"sectionNum"] integerValue]==0) {
//this is user is online
[[[AKSGetCareerGlobalClass SharedInstance] onlineUserArray] addObject:[[[self xmppUserArray] objectAtIndex:i] valueForKey:@"nickname"]];
}
}
//also implement method
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
//remove previous data or clear array
[[self xmppUserArray] removeAllObjects];
[[[AKSGetCareerGlobalClass SharedInstance] onlineUserArray] removeAllObjects];
//get data from core data
self.xmppUserArray=[[[self fetchedResultsController] fetchedObjects] mutableCopy];
for (int i=0; i<[[self xmppUserArray] count]; i++) {
if ([[[[self xmppUserArray] objectAtIndex:i] valueForKey:@"sectionNum"] integerValue]==0) {
//this is user is online
[[[AKSGetCareerGlobalClass SharedInstance] onlineUserArray] addObject:[[[self xmppUserArray] objectAtIndex:i] valueForKey:@"nickname"]];
}
}
[[self msgTableView] reloadData];
}
-(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];
//NSSortDescriptor *sd2 = [[NSSortDescriptor alloc] initWithKey:@"displayName" ascending:YES];
//NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:@"userJID"];
//NSLog(@"My JID ====>%@",myJID);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"subscription=='both'"];//take care about subscription
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setFetchBatchSize:20];
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;
}
视图中将出现
//xmpp用户阵列
self.xmppUserArray=[[[self-fetchedResultsController]fetchedObjects]mutableCopy];
对于(int i=0;i