views:

139

answers:

1

Hello, I'm trying to get the IM account information from existing contacts (adressbook) on iPhone. I walk through the contacts and I get the contacts which have an entry in IM but I can't read the jabber-address.

abArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(ABAddressBookCreate());

for(int i=0 ; i<[abArray count];i++)
{
  ABRecordRef record = [abArray objectAtIndex:i];

  ABMutableMultiValueRef multi = ABRecordCopyValue(record, kABPersonInstantMessageProperty);

  for(CFIndex x=0;x<ABMultiValueGetCount(multi);x++)
  {
   CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, x);
   CFStringRef jabber = CFDictionaryGetValue(dict, kABPersonInstantMessageServiceJabber);

   if(CFDictionaryContainsKey(dict, kABPersonInstantMessageServiceJabber))
   {
    NSLog(@"yes");
   }
   else {
    NSLog(@"no");
   }

   // only to make it possible to log to console   
   NSString *jaab = (NSString *)jabber;
   NSLog(@"jabber adress: %@" , jaab);
   }
   CFRelease(dict);
  }
}

what I'm doing wrong?

A: 
for(int i=0 ; i<[abArray count];i++)
{
    ABRecordRef record = [abArray objectAtIndex:i];
    ABMutableMultiValueRef multi = ABRecordCopyValue(record, kABPersonInstantMessageProperty);

    for(CFIndex x=0;x<ABMultiValueGetCount(multi);x++)
    {
        CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, x);
        CFStringRef jabber;


        //Use this piece of code to print the dict to log and check

        NSDictionary *nsdict = (NSDictionary *)dict;
        NSString *jabberID = [NSString stringWithString:@""];
        NSLog(@"Dict: %@", nsdict);
        if([[nsdict valueForKey:@"service"] isEqualToString:@"Jabber"]){
            jabberID = [nsdict valueForKey:@"username"];
        }
        //Code to print dict to log ends here. Comment the whole piece if not needed.


        if(CFStringCompare((CFStringRef)@"jabber", CFDictionaryGetValue(dict, @"service"), 0))
        {
            NSLog(@"yes");
            jabber = CFDictionaryGetValue(dict, @"username");

            // only to make it possible to log to console  
            NSString *jaab = (NSString *)jabber;
            NSLog(@"jabber adress: %@" , jaab);
        }
        else {
            NSLog(@"no");
        }

    }
    //CFRelease(dict);
}
Siddhartha Gutha
CFDictionaryContainsKey(dict, kABPersonInstantMessageServiceJabber)The dictionary dict does not contain the key kABPersonInstantMessageServiceJabber. But if you try out the above code, you might get a better understanding on the key-value pairs in the dict.
Siddhartha Gutha