【发布时间】:2014-11-06 07:58:27
【问题描述】:
我正在在线/离线获得用户的存在。这样,如果我需要检查,我必须每次都发送请求才能获得存在
如何检查多个用户或仅在线用户?
【问题讨论】:
标签: ios xmpp openfire xmppframework
我正在在线/离线获得用户的存在。这样,如果我需要检查,我必须每次都发送请求才能获得存在
如何检查多个用户或仅在线用户?
【问题讨论】:
标签: ios xmpp openfire xmppframework
我已经实现了 NSFetchedResultsControllerDelegate。我正进入(状态 “SectionNum”=0 中的在线用户列表。每当用户去 离线/在线控制器的委托方法调用。相应地更新 表格视图。
// 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;
}
【讨论】:
使用服务器上的在线用户插件。这样就可以通过http获取在线用户了。
【讨论】: