How to receive an email using ABPeoplePicker?

I do not find the Apple documentation very useful for actually retrieving data using a people collector, and there seems to be no other information on the Internet :( I assume I need to receive an email in this function:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{

}

What can I add there to receive the email of the selected person?

+1
source share
2 answers

Using

ABMultiValueRef emails = ABRecordCopyValue(record, kABPersonEmailProperty);

After that, you can use the ABMultiValueRefs API method calls to get the email address.

EDIT - this should give you an email address

CFStringRef emailId = ABMultiValueCopyValueAtIndex(emails, identifier);
0
source

Kal , , "ABMultiValueCopyValueAtIndex" .

(, )

  • " " "0"
  • " " "1".

, , 1 , " ". "1", "0".

, , :

int index = ABMultiValueGetIndexForIdentifier(emails, identifier);

:

if (property == kABPersonEmailProperty) {

    ABMultiValueRef emails = ABRecordCopyValue(person, property);

    NSString *count = [NSString stringWithFormat:@"Count: %d Identifier: %d", ABMultiValueGetCount(emails), identifier];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:count delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    if(ABMultiValueGetCount(emails) > 0)
    {
        int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
        CFStringRef emailTypeSelected = ABMultiValueCopyLabelAtIndex(emails, index);
        CFStringRef emailTypeSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, index));
        CFStringRef emailValueSelected = ABMultiValueCopyValueAtIndex(emails, index);

        self.lblEmailType.text = (NSString *) emailTypeSelected;
        self.lblEmailTypeLocalized.text = (NSString *) emailTypeSelectedLocalized;
        self.lblEmailValue.text = (NSString *) emailValueSelected;
    }

    [ self dismissModalViewControllerAnimated:YES ];
    return NO;
}

return YES;
+4

Source: https://habr.com/ru/post/1543261/


All Articles