我正在尝试获取特定来源的联系人,但它会返回给我0对象。
就像你看到源是否有组它将添加到阵列,但如果没有组我只需要知道此源中的联系人数“例如Google,Facebook,..”
for (CFIndex i = 0; i < CFArrayGetCount(allSources); i++)
{
ABRecordRef aSource = CFArrayGetValueAtIndex(allSources,i);
// Fetch all groups included in the current source
CFArrayRef result = ABAddressBookCopyArrayOfAllGroupsInSource (myAddressBook, aSource);
// The app displays a source if and only if it contains groups
if (CFArrayGetCount(result) > 0)
{
NSMutableArray *groups = [[NSMutableArray alloc] initWithArray:(NSArray *)result];
// Fetch the source name
NSString *sourceName = [self nameForSource:aSource];
//Create a MySource object that contains the source name and all its groups
MySource *source = [[MySource alloc] initWithAllGroups:groups name:sourceName];
// Save the source object into the array
[list addObject:source];
[source release];
[groups release];
}
else
{
CFArrayRef result= ABAddressBookCopyArrayOfAllPeopleInSource(myAddressBook, aSource);
}
CFRelease(result);
}