gpt4 book ai didi

ios - 任何人都可以建议我如何获取我的 friend 列表个人资料图片和状态

转载 作者:行者123 更新时间:2023-11-29 11:54:58 26 4
gpt4 key购买 nike

目前我正在开发基于聊天的应用程序。我已成功上传我的个人资料图片。任何人都可以建议我如何获取我的 friend 列表、个人资料图片和状态。我尝试了下面的代码。我正在使用 XMPP 聊天框架。

此代码用于检索我自己的 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,则状态:可用,如果状态为 1:离开,否则为离线

- (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];

希望对您有所帮助。快乐的编码......

关于ios - 任何人都可以建议我如何获取我的 friend 列表个人资料图片和状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39569078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com