온라인/오프라인 사용자가 있습니다. 이 방법은 내가 확인해야 할 때마다 요청을 보낼 때마다 존재를 얻을 수iOS의 openfire/xmpp에있는 모든 온라인 사용자 목록을 얻으려면 어떻게해야합니까?
어떻게 여러 사용자 또는 온라인 사용자를 확인할 수 있습니까?
온라인/오프라인 사용자가 있습니다. 이 방법은 내가 확인해야 할 때마다 요청을 보낼 때마다 존재를 얻을 수iOS의 openfire/xmpp에있는 모든 온라인 사용자 목록을 얻으려면 어떻게해야합니까?
어떻게 여러 사용자 또는 온라인 사용자를 확인할 수 있습니까?
서버의 온라인 사용자 플러그인을 사용하십시오. 이렇게하면 http를 통해 온라인 사용자를 얻을 수 있습니다. https://github.com/candy-chat/onlineUsersPlugin
내가 NSFetchedResultsControllerDelegate를 구현하고 있습니다 여기에
는 링크입니다. 나는 "SectionNum"= 0의 온라인 사용자 목록을 얻고 있습니다. 사용자가 갈 때마다 오프라인/온라인 컨트롤러의 대리자 메서드가 호출됩니다. 해당 업데이트 tableView.
// 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;
}