我想从通讯录中选择多个联系人,并且我想将所选人员的图像存储在一个可变数组中。我已经完全搜索了互联网,但我无法获得任何样品。任何人请帮助
提前致谢
我想从通讯录中选择多个联系人,并且我想将所选人员的图像存储在一个可变数组中。我已经完全搜索了互联网,但我无法获得任何样品。任何人请帮助
提前致谢
首先,您必须添加
“AddressBook.framework”框架并添加头文件:
// 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);
}