Domanda

Sto cercando di recuperare la proprietà e-mail selezionata nella callback delegata menzionata sotto

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

Ma se seleziono la proprietà Email del contatto collegato (con singola e-mail) ottengo l'identificatore come 0, di conseguenza ottengo il primo email-ID del contatto primario. Ad esempio: john - john@gmail.com john26@gmail.com. Roger (contatto collegato) - roger@gmail.com

Quando selezionerò roger@gmail.com ottengo john@gmail.com.

È stato utile?

Soluzione

Ho questo stesso problema.Ottengo l'email sbagliata quando seleziono account con più indirizzi e-mail.Quando loop attraverso l'abmutablemultivaleuerereref selezionato ...

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

... ottengo più occorrenze dello stesso indirizzo, ma alcuni con etichette null.

> 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 soluzione alternativa proverò è quella di filtrare prima le etichette null, vedere se l'abmisitivalidentificatore "si adatta" e se non ripristina le etichette null.A meno che tu non abbia trovato qualcosa?

Modifica: funziona per me.

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top