2012-02-09 93 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....