ios - 如何在 iOS 的 openfire/xmpp 中获取所有在线用户的列表?
<p><p>我正在在线/离线获得用户的存在。这样,如果我需要检查,我必须每次都发送请求才能获得存在</p>
<p>如何检查多个用户或仅在线用户?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><blockquote>
<p>I have implement NSFetchedResultsControllerDelegate. i am getting
list of Online user in "SectionNum"=0. whenever user goes
offline/online controller's delegate method called.accordingly update
tableView.</p>
</blockquote>
<p>//NSFetchedResultsController *fetchedResultsController;//实例变量</p>
<pre><code>in viewWillAppear
//xmpp user array
self.xmppUserArray=[[ fetchedObjects] mutableCopy];
for (int i=0; i<[ count]; i++) {
if ([[[ objectAtIndex:i] valueForKey:@"sectionNum"] integerValue]==0) {
//this is user is online
[[ onlineUserArray] addObject:[[ objectAtIndex:i] valueForKey:@"nickname"]];
}
}
//also implement method
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
//remove previous data or clear array
[ removeAllObjects];
[[ onlineUserArray] removeAllObjects];
//get data from core data
self.xmppUserArray=[[ fetchedObjects] mutableCopy];
for (int i=0; i<[ count]; i++) {
if ([[[ objectAtIndex:i] valueForKey:@"sectionNum"] integerValue]==0) {
//this is user is online
[[ onlineUserArray] addObject:[[ objectAtIndex:i] valueForKey:@"nickname"]];
}
}
[ reloadData];
}
-(NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController == nil)
{
NSManagedObjectContext *moc = [ managedObjectContext_roster];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"XMPPUserCoreDataStorageObject"
inManagedObjectContext:moc];
NSSortDescriptor *sd1 = [ initWithKey:@"sectionNum" ascending:YES];
NSSortDescriptor *sd2 = [ initWithKey:@"displayName" ascending:YES];
NSArray *sortDescriptors = ;
//NSSortDescriptor *sd2 = [ initWithKey:@"displayName" ascending:YES];
//NSString *myJID = [ stringForKey:@"userJID"];
//NSLog(@"My JID ====>%@",myJID);
NSPredicate *predicate = ;//take care about subscription
NSFetchRequest *fetchRequest = [ init];
;
;
;
;
fetchedResultsController = [ initWithFetchRequest:fetchRequest
managedObjectContext:moc
sectionNameKeyPath:@"sectionNum"
cacheName:nil];
;
NSError *error = nil;
if (!)
{
DDLogError(@"Error performing fetch: %@", error);
}
}
return fetchedResultsController;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 iOS 的 openfire/xmpp 中获取所有在线用户的列表?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25803196/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25803196/
</a>
</p>
页:
[1]