我正在尝试从iOS上现有的AddressBook
个联系人处获取即时消息帐户信息。我浏览了联系人,我得到了具有即时消息传递值的联系人,但我无法读取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);
}
}
我做错了什么?
答案 0 :(得分: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);
}