Forum Navigation
You need to log in to create posts and topics.

copyEmailForName:

Posted by: fbcocoa.bw <fbcocoa.bw@...>

EmailForName (posted on the main list) looks quite different for the iPhone. The address book must be accessed via a set of C functions plus it appears that ABSearchElement is not available.
- (NSString *)copyEmailForName:(NSString *)name emailLabel:(NSString *)emailLabel {
NSString *email = nil;


ABAddressBookRef ab = ABAddressBookCreate();
if ( ab != nil ) {
CFArrayRef people = ABAddressBookCopyPeopleWithName( ab, (CFStringRef)name );
if ( people != nil ) {
if ( CFArrayGetCount( people ) > 0 ) {
ABRecordRef person = CFArrayGetValueAtIndex( people, 0 );
ABMultiValueRef mv = ABRecordCopyValue( person, kABPersonEmailProperty );
if ( mv != nil ) {
CFIndex mvCount = ABMultiValueGetCount( mv ) - 1;
while ( mvCount >= 0 && email == nil ) {
CFStringRef label = ABMultiValueCopyLabelAtIndex( mv, mvCount );
if ( CFEqual( label, emailLabel ) )
email = (NSString *)ABMultiValueCopyValueAtIndex( mv, mvCount );
CFRelease( label );
mvCount--;
}
CFRelease( mv );
}
}
CFRelease( people );
}
CFRelease( ab );
}
return email;
}
Bernie




To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]