Question

J'essaie d'aller chercher une propriété de courrier électronique sélectionnée dans le rappel de délégué mentionné ci-dessous

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

Mais si je sélectionne la propriété de messagerie du contact lié (avoir un email unique), je reçois l'identifiant comme 0, ce qui obtient le premier identifiant de messagerie de contact principal. Par exemple: John - John@gmail.com john26@gmail.com Roger (contact lié) - Roger@gmail.com

Quand je sélectionne roger@gmail.com, je reçois John@gmail.com.

Était-ce utile?

La solution

J'ai le même problème.Je reçois le mauvais email lorsque je sélectionne des comptes avec plusieurs adresses électroniques.Quand je boucle à travers la sélection sélectionnée AbmutablrultivivallUref ...

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

... Je reçois plusieurs occurrences de la même adresse, mais certaines avec des étiquettes 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 solution de contournement J'essaierai est de filtrer d'abord les étiquettes NULL, voir si l'ABMultiviIdentifier 'Convient', et si vous ne retournez pas les étiquettes NULL.Sauf si vous avez trouvé quelque chose?

Edit: Cela fonctionne pour moi.

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top