¿Cómo obtengo la cuenta de personas de las fuentes externas usando abaddressbookcopyarrayofallpeopleinsourcewithsordoring ()

StackOverflow https://stackoverflow.com/questions/5062968

Pregunta

Estoy tratando de obtener personas en tres fuentes (1 fuente de MobileMe y 2 * fuentes de Tierresgales) de mi libreta de direcciones IOS 4.
La declaración de NSLOG siempre devuelve a 0 personas para TIropegergente, pero devuelve un conde de personas para MobileMe.
Después de obtener todas las fuentes de la libreta de direcciones de iOS mediante el uso de abaddressbookcopyarrayofallsources (LISTOUBIERNO), estoy intentando iterar la fuente por fuente para obtener más información para cada fuente.

¿Estoy usando el abaddressbookcopyarrayofallpeopleinsourcewithsordenando correctamente? Esperaría un recuento de todas las personas en las diferentes fuentes de la libreta de direcciones.

-(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];
    }
}

editar feb24: Parece que funciona el código, pero tengo un problema para conseguir que las personas cuentan con las exhortegales.
¿Alguien ha recuperado con éxito a las personas de TierGergal? La fuente de MobileMe reporta un recuento de personas.
Aquí está el registro de la consola:

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

¿Fue útil?

Solución

Try Using:

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);
}

You might find this helpful :abaddressbook-absource-and-absourcetype

Otros consejos

Are the people you're expecting to return actually in your addressbook? You shouldn't expect ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering() to return the entire GAL. That would be massive. You should only expect it to return a subset of ABAddressBookCopyArrayOfAllPeople().

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top