1

我正在尝试从AddressBookiOS 上的现有联系人获取即时消息帐户信息。我浏览了联系人,我得到了具有即时消息传递价值的联系人,但我无法读取 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);
  }
}

我究竟做错了什么?

4

1 回答 1

0
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);
}
于 2010-03-26T14:33:10.350 回答