Currently i am working chat based application.I am successfully upload my profile picture. Can any one suggest me how to get my friends list, Profile picture and status. I tried below code.I am using XMPP
Framework for Chat.
This code for retriving my own Prifile picture
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()];
Fetch the user object from the XMPPUserCoreData, then use the user object to get the photo and name of user lists.
I use this code to fetch user. After user is fetched You can use user.photo
to get user image, user.displayName
to get user name, and section property of object of NSFetchedResultsController
, to get status. If section value is 0 then status : Available
, if status is 1 : Away
, else 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;
}
For getting number of sections -> count
NSArray *sections = [[self fetchedResultsControllerContacts] sections];
For getting number of rows in one section in numberOfRowsInSection
method
if (section < [sections count])
{
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:sectionIndex];
return sectionInfo.numberOfObjects;
}
For getting single user Inside cellForRowAtIndexPath
XMPPUserCoreDataStorageObject *user = [[self fetchedResultsControllerContacts] objectAtIndexPath:indexPath];
Hope it helps. Happy coding ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.