我正在尝试创建一个具有自定义界面的应用程序,用于搜索一个人的通讯录。搜索本地通讯录似乎很容易,但我不知道如何在 Exchange 通讯录源中搜索个人/记录(即 ABSourceType == kABSourceTypeExchangeGAL)。我正在使用以下代码查找 Exchange 通讯录源并对其进行查询,但我只得到一个空数组。我知道在 Exchange 通讯录中询问整个人员列表不可能返回所有条目,但是当我查询它时,我会期望该列表的某个子集。同样,我得到一个空数组。
如何在 Exchange 通讯录源中搜索联系人?
#define CFNIL(x) if(x){CFRelease(x); x=nil;}
//code
ABAddressBookRef _addressbook = ABAddressBookCreate();
CFArrayRef allSources = ABAddressBookCopyArrayOfAllSources(_addressbook);
ABRecordRef exchangeSource;
for(CFIndex i =0; i<CFArrayGetCount(allSources); i++)
{
ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(allSources, i);
NSNumber *sourceTypeNumber = (NSNumber*)((CFNumberRef)ABRecordCopyValue(source, kABSourceType));
NSString *sourceTypeName = (NSString *)((CFStringRef)ABRecordCopyValue(source, kABSourceNameProperty));
int sourceType = [sourceTypeNumber intValue];
if (sourceType == kABSourceTypeExchangeGAL)
{
exchangeSource = source;
}
[sourceTypeNumber release];
[sourceTypeName release];
}
if(exchangeSource)
{
/*
This finds matches in the local device addressbook
NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(_addressbook, CFSTR("joe"));
for(int i=0;i<[people count]; i++)
{
ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];
ABMultiValueRef emails = (ABMultiValueRef)ABRecordCopyValue(person, kABPersonEmailProperty);
NSLog(@"emails: %@",emails);
[((NSArray*)emails) release];
}
[people release];
*/
//this array is always empty
CFArrayRef search = ABAddressBookCopyArrayOfAllPeopleInSource (_addressbook,exchangeSource);
NSLog(@"%@", search);
CFNIL(search);
}
CFNIL(exchangeSource);
CFNIL(_addressbook);