Pregunta

Estoy tratando de buscar la propiedad de correo electrónico seleccionada en Delegate Callback mencionado a continuación

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
        if (property==kABPersonEmailProperty) {
            ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
            if (ABMultiValueGetCount(emails) > 0) {
                NSString *email = (__bridge_transfer NSString*)
                ABMultiValueCopyValueAtIndex(emails, ABMultiValueGetIndexForIdentifier(emails,identifier));
                [recipientEmail setText:email];
                [peoplePicker dismissViewControllerAnimated:YES completion:nil];
            }
             CFRelease(emails);
        }
        return NO;
    }

Pero si selecciono la propiedad de correo electrónico del contacto vinculado (teniendo un correo electrónico único), obtengo el identificador como 0, como resultado, obtengo el primer correo electrónico de contacto primario. EG: John - john@gmail.com john26@gmail.com Roger (contacto vinculado) - roger@gmail.com

Cuando selecciono a roger@gmail.com Obtengo john@gmail.com.

¿Fue útil?

Solución

Tengo este mismo problema.Recibo el correo electrónico equivocado cuando selecciono cuentas con varias direcciones de correo electrónico.Cuando bucle a través de la abmutablemultivalueref seleccionada ...

for (CFIndex ix = 0; ix < ABMultiValueGetCount(emails); ix++) {
   CFStringRef label = ABMultiValueCopyLabelAtIndex(emails, ix);
   CFStringRef value = ABMultiValueCopyValueAtIndex(emails, ix);
   NSLog(@"I have a %@ address: %@", label, value);
   if (label) CFRelease(label);
   if (value) CFRelease(value);
}

... Tengo múltiples ocurrencias de la misma dirección, pero algunas con etiquetas nulas.

> I have a (null) address: john@home.com
> I have a _$!<Work>!$_ address: jsmith@work.com
> I have a _$!<Home>!$_ address: john@home.com

La solución que intentaré es filtrar primero las etiquetas nulas primero, consulte si el "ajuste" de abmultivalueidentificador ", y si no vuelve a las etiquetas nulas.A menos que haya encontrado algo?

Editar: Esto funciona para mí.

    NSMutableArray *labeled = [NSMutableArray new];
    ABMutableMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
    for (CFIndex ix = 0; ix < ABMultiValueGetCount(emails); ix++) {
        CFStringRef label = ABMultiValueCopyLabelAtIndex(emails, ix);
        CFStringRef value = ABMultiValueCopyValueAtIndex(emails, ix);
        if (label != NULL) {
            [labeled addObject:(NSString *)CFBridgingRelease(value)];
        }
        if (label) CFRelease(label);
        if (value) CFRelease(value);
    }
    NSString *email;
    if (labeled.count > identifier) {
        email = [labeled objectAtIndex:identifier];
    } else {
        CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, identifier);
        email = (NSString *)CFBridgingRelease(emailRef);
    }

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