Skip to content

Instantly share code, notes, and snippets.

@nestserau
Created February 6, 2010 11:52
Show Gist options
  • Save nestserau/296671 to your computer and use it in GitHub Desktop.
Save nestserau/296671 to your computer and use it in GitHub Desktop.
Picking an email address from Address Book with no fail
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)
peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
ABMultiValueRef emails = ABRecordCopyValue(person, property);
CFStringRef email = ABMultiValueCopyValueAtIndex(emails, identifier);
NSString *str = [textField text];
if (![str isEqualToString:@""]) {
str = [NSString stringWithFormat:@"%@, %@", str, email];
} else {
str = (NSString *)email;
}
[textField setText:str];
[controller dismissModalViewControllerAnimated:YES];
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)
peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
ABMultiValueRef emails = ABRecordCopyValue(person, property);
NSArray *emailArray = [(id)ABMultiValueCopyArrayOfAllValues(emails)
autorelease];
const NSUInteger emailIndex = ABMultiValueGetIndexForIdentifier(emails,
identifier);
NSString *email = [emailArray objectAtIndex:emailIndex];
NSString *str = [textField text];
if (![str isEqualToString:@""]) {
str = [NSString stringWithFormat:@"%@, %@", str, email];
} else {
str = (NSString *)email;
}
[textField setText:str];
[controller dismissModalViewControllerAnimated:YES];
return NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment