2012-02-09 96 views
0

如何只從地址簿,選擇聯繫人的Twitter的詳細如何獲取只能從結果集

if (property == kABPersonSocialProfileProperty) { 

     ABMultiValueRef multi = ABRecordCopyValue(person, property); 


     for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) { 

      CFStringRef socialLabel = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multi, identifier)); 

      CFStringRef social = ABMultiValueCopyValueAtIndex(multi, i); 

      NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(multi, i);   

      NSString*twitterdetails = [personaddress valueForKey:(NSString *)kABPersonSocialProfileServiceTwitter]; 
      NSLog(@"%@ twitterdetails",twitterdetails); 


      NSString *aString = (NSString *)social; 


      NSLog(@"%@ aString",aString); 
     } 

我得到的結果如下時,你得到的用戶名值的用戶名

{ 
    service = twitter; 
    url = "http://twitter.com/manoas2136"; 
    username = manoas2136; 
} aString 

請告訴我如何從上述結果只得到用戶名設定

回答

3

試試這個代碼

NSDictionary* personalDetails = [NSDictionary dictionaryWithDictionary:(NSDictionary*)ABMultiValueCopyValueAtIndex(multi, i)]; 
    NSString* aString = [personalDetails valueForKey:@"username"]; 
    NSLog(@"%@ aString",aString); 

結果manoas2136 ASTRING

您在轉換的NSDictionary的值串,因此杵NSDictionary中的所有結果的NSString,所以你只提取使用valueForKey用戶名:

+0

感謝很多傢伙......它的工作原理..你真的幫了我...... – user198725878 2012-02-09 12:07:43

0

我已經試過這種方式來獲取來自iphone聯繫人列表的Twitter地址。它工作正常..

ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonSocialProfileProperty); 

for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) 
{ 

    NSDictionary* personalDetails = [NSDictionary dictionaryWithDictionary:(NSDictionary*)ABMultiValueCopyValueAtIndex(multi, i)]; 
    NSLog(@"%@",personalDetails); 

    NSString* aString1 = [personalDetails valueForKey:@"username"]; 
    NSLog(@"%@ aString",aString1); 
    Twitter.text = [personalDetails valueForKey:@"username"]; 
} 
//get Twitter Address end....