2016-09-19 3 views
1

現在、私はチャットベースのアプリケーションを使っています。プロフィール画像をアップロードしています。私の友人のリスト、プロフィールの画像とステータスを取得する方法を教えてください。私は以下のコードを試しました。私はXMPP Framework for Chatを使用しています。私の友達リストを取得する方法を教えてもらえますか?プロフィール画像とステータス

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

答えて

1

は、ユーザリストの写真と名前を取得するには、ユーザオブジェクトを使用し、XMPPUserCoreDataからユーザーオブジェクトを取得し、私自身Prifile画像をretrivingためのこのコードは。

私はこのコードを使用してユーザーを取得します。ユーザーがフェッチされた後、ユーザーイメージを取得するためにuser.photo、ユーザー名を取得するためにuser.displayName、オブジェクトのセクションプロパティNSFetchedResultsControllerを使用してステータスを取得できます。 セクションの値は、ステータス0の場合:Available、ステータスが1の場合:セクションの数を取得するための他の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; 
} 

Away、 - >数1つのセクション内の行数を取得するための

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

希望すると助かります。 ハッピーコーディング...

+0

クイックレスポンス(fetchedUserLists == nil)ありがとう、私はこのステートメントを理解しませんでした。 –

+0

これは "NSFetchedResultsController"タイプのグローバル変数です。あなたは自分自身を取ることができます – Janmenjaya

+0

こんにちは、私は完全なソースコードを教えてください –

関連する問題