How to get the number of people from ExchangeGal sources using ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering ()

I am trying to attract people from three sources (1 MobileMe source and 2 * ExchangeGAL sources) from my iOS 4 address book.
The NSLog operator always returns 0 people for ExchangeGAL, but returns the number of people for MobileMe.
After getting all the sources from the iOS address book using ABAddressBookCopyArrayOfAllSources (addressBook), I try to iterate the source by source to get more information for each source.

Am I using ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering correctly?
It would expect counting all the people in different sources of the address book.

-(void)countPeopleInSources
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef allSources = ABAddressBookCopyArrayOfAllSources(addressBook);
    for (CFIndex i = 0; i < CFArrayGetCount(allSources); i++) 
    {
        ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(allSources, i);
        NSNumber *sourceTypeRef = (NSNumber *)((CFNumberRef)ABRecordCopyValue(source, kABSourceTypeProperty));
        ABPersonSortOrdering sortOrdering = ABPersonGetSortOrdering();
        int sourceType = [sourceTypeRef intValue];
        switch (sourceType) {
        case kABSourceTypeCardDAV:
            NSLog(@"SourceTypeCardDAV");
            break;
        case kABSourceTypeCardDAVSearch:
            NSLog(@"SourceTypeCardDAVSearch");
            break;
        case kABSourceTypeExchange:
            NSLog(@"SourceTypeExchange");
            break;
        case kABSourceTypeExchangeGAL:
            NSLog(@"SourceTypeExchangeGAL");
            break;
        case kABSourceTypeLDAP:
            NSLog(@"SourceTypeLDAP");
            break;
        case kABSourceTypeLocal:
            NSLog(@"SourceTypeLocal");
            break;
        case kABSourceTypeMobileMe:
            NSLog(@"SourceTypeMobileMe"); 
            break;
        default:
            break;
    }
        CFArrayRef allPeopleInSource = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, sortOrdering );
        NSLog(@"Count allPeopleInSource: %i", CFArrayGetCount(allPeopleInSource));

        [sourceTypeRef release];
    }
}

EDIT FEB24: , , ExhangeGAL.
- ExchangeGAL?
MobileMe .
:

2011-02-24 07:04:32.578 Contacts[10099:307] SourceTypeExchangeGAL
2011-02-24 07:04:32.593 Contacts[10099:307] Count allPeopleInSource: 0
2011-02-24 07:04:32.597 Contacts[10099:307] SourceTypeMobileMe
2011-02-24 07:04:32.641 Contacts[10099:307] Count allPeopleInSource: 151
2011-02-24 07:04:32.646 Contacts[10099:307] SourceTypeExchangeGAL
2011-02-24 07:04:32.652 Contacts[10099:307] Count allPeopleInSource: 0
+5
2

:

ABRecordRef sourceWithType (ABSourceType mySourceType)
{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);
CFIndex sourceCount = CFArrayGetCount(sources);
ABRecordRef resultSource = NULL;
for (CFIndex i = 0 ; i < sourceCount; i++) {
    ABRecordRef currentSource = CFArrayGetValueAtIndex(sources, i);
    ABSourceType sourceType = [(NSNumber *)ABRecordCopyValue(currentSource, kABSourceTypeProperty) intValue];
    if (mySourceType == sourceType) {
        resultSource = currentSource;
        break;
    }
}

return resultSource;
}

ABRecordRef localSource()
{
    return sourceWithType(kABSourceTypeLocal);
}

ABRecordRef exchangeSource()
{
     return sourceWithType(kABSourceTypeExchange);
}

ABRecordRef mobileMeSource()
{
     return sourceWithType(kABSourceTypeMobileMe);
}

: abaddressbook-absource-and-absourcetype

+1

, ? , ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering() GAL. . , ABAddressBookCopyArrayOfAllPeople().

+2

All Articles