开发者

Retrieving instant message information from an ABRecordRef

I'm trying to get the instant message account information from existing AddressBook contacts on iOS. I walk through the contacts and I get the contacts which have an instant messaging value, 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];

  ABMutableMul开发者_如何学CtiValueRef 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 am I doing wrong?


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜