任何人可以建议我如何得到我的朋友列表个人资料图片和状态
问题描述:
目前我在工作基于聊天的应用程序。我成功上传了我的个人资料图片。任何人都可以告诉我如何获得我的朋友列表,个人资料图片和状态。我尝试了下面的代码。我正在使用XMPP
框架聊天。任何人可以建议我如何得到我的朋友列表个人资料图片和状态
此代码为retriving我自己Prifile图片
xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
xmppvCardTempModule= [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
XMPPvCardAvatarModule *xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];
XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@localhost",str]];
NSData *avtarData = [xmppvCardAvatarModule photoDataForJID:jid];
**This code for Upload my own Prifile picture**
NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
XMPPvCardTemp *newvCardTemp = [XMPPvCardTemp vCardTempFromElement:vCardXML];
[newvCardTemp setGivenName:@"gireesh"];
[newvCardTemp setSortString:@"Chanti"];
NSArray *arr1= [[NSUserDefaults standardUserDefaults]objectForKey:@"USER"];
[[NSUserDefaults standardUserDefaults]synchronize];
DLog(@"user Profile %@",[arr1 objectAtIndex:0]);
DLog(@"user Profile %@",[arr1 objectAtIndex:1]);
NSString *str = [NSString stringWithFormat:@"%@%@",[arr1 objectAtIndex:1],[arr1 objectAtIndex:0]];
[newvCardTemp setJid:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@localhost",str]]];
[newvCardTemp setFormattedName:@""];
[newvCardTemp setEmailAddresses:[getdic valueForKey:@"emailid"]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imageFilePath = [documentsDirectory stringByAppendingPathComponent:@"Profileimage"];
UIImage* image1 = [UIImage imageWithContentsOfFile:imageFilePath];
NSData *imageData1 = UIImagePNGRepresentation(image1);
[newvCardTemp setPhoto:imageData1];
[xmppvCardTempModule updateMyvCardTemp:newvCardTemp];
[xmppvCardTempModule activate:[self appDelegate].xmppStream];
[xmppvCardTempModule addDelegate:self delegateQueue:dispatch_get_main_queue()];
答
从XMPPUserCoreData获取用户对象,然后使用用户对象来获取用户列表的照片和名字。
我使用此代码来获取用户。获取用户后您可以使用user.photo
获取用户图像,user.displayName
获取用户名和NSFetchedResultsController
对象的section属性以获取状态。 如果部分值为0,则状态:Available
,如果状态为1:Away
,否则Offline
- (NSFetchedResultsController *)fetchedResultsControllerContacts
{
if (fetchedUserLists == nil)
{
NSManagedObjectContext *moc = [[AppDelegate delegate] 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];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setFetchBatchSize:10];
fetchedUserLists = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:moc
sectionNameKeyPath:@"sectionNum"
cacheName:nil];
[fetchedUserLists setDelegate:(id)self];
NSError *error = nil;
if (![fetchedUserLists performFetch:&error])
{
DDLogError(@"Error performing fetch: %@", error);
}
}
return fetchedUserLists;
}
为了得到区间的数目 - >计数
NSArray *sections = [[self fetchedResultsControllerContacts] sections];
为了得到在一个部分中的行数在numberOfRowsInSection
方法
if (section < [sections count])
{
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:sectionIndex];
return sectionInfo.numberOfObjects;
}
获取单个用户 里面cellForRowAtIndexPath
XMPPUserCoreDataStorageObject *user = [[self fetchedResultsControllerContacts] objectAtIndexPath:indexPath];
希望它能帮助。 快乐编码...
感谢您的快速Response.if(fetchedUserLists ==零)这是什么,我不明白这个说法。你从它得到 –
这是一个全局变量的类型“NSFetchedResultsController”。你可以把你自己的 – Janmenjaya
嗨可以ü请给出完整的源代码 –