I want to select multiple contacts from an address book and i want to store the images of the selected persons in an mutable array. I have searched through the internet completely but i cant get any samples. Any one please help
Thanks in advance
I want to select multiple contacts from an address book and i want to store the images of the selected persons in an mutable array. I have searched through the internet completely but i cant get any samples. Any one please help
Thanks in advance
First You have to add the
"AddressBook.framework" framework and add header file :
// this method
#pragma mark- find all contacts email id
-(void)getFilterEmailid{
NSUInteger i;
NSUInteger k;
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
if ( people==nil )
{
NSLog(@"NO ADDRESS BOOK ENTRIES TO SCAN");
CFRelease(addressBook);
return;
}
for ( i=0; i<[people count]; i++ )
{
ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];
NSString *home=@"";
NSString *work=@"";
//
// Phone Numbers
//
ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonEmailProperty);
CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers );
// Here we can get the Image ref
CFDataRef imageData = ABPersonCopyImageData(person);
// This is the Image Data you can use as you want to.
NSData *data = (NSData *)imageData;
for ( k=0; k<phoneNumberCount; k++ )
{
CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, k );
CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, k );
CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel ); // converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"
// Find the ones you want here
//
NSLog(@"-----PHONE ENTRY -> %@ : %@", phoneNumberLocalizedLabel, phoneNumberValue );
home=[(NSString*)phoneNumberLocalizedLabel copy ];
work=[(NSString *)phoneNumberValue copy];
NSLog(@"home=%@ work=%@",home,work);
CFRelease(phoneNumberLocalizedLabel);
CFRelease(phoneNumberLabel);
CFRelease(phoneNumberValue);
// This is my array i save only the Email id. You can save what value you want
[emailIdArray addObject:work];
}
}
[people release];
CFRelease(addressBook);
}