You need to log in to create posts and topics.
copyEmailForName:
1,678 Posts
#1 · July 11, 2010, 1:05 am
Quote from Forum Archives on July 11, 2010, 1:05 amPosted 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]
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]
Click for thumbs down.0Click for thumbs up.0