I am using kABPersonPhoneProperty to get the iPhone "phone numbers" from the address book. However, once I run the program and only one phone number appears even the contact person has mobile, home and iphone numbers. Please help and I hope can get all phone numbers from every contact. Thanks.
The full method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
// cell.textLabel.text = [people objectAtIndex:indexPath.row];
ABRecordRef record = (__bridge ABRecordRef) [people objectAtIndex:[indexPath row]];
NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(record, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString*)ABRecordCopyValue(record, kABPersonLastNameProperty);
NSLog(#"FirstName %#, LastName %#", firstName, lastName);
cell.nameLabel.text = [NSString stringWithFormat:#"%# %#", firstName, lastName];
ABMultiValueRef mainPhone = ABRecordCopyValue(record, kABPersonPhoneProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(mainPhone); i ++) {
NSString *phoneMobileNumber = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(mainPhone, i);
cell.telNo.text = [NSString stringWithFormat:#"%# %#" , home, phoneMobileNumber];
NSLog(#"%#,%#", home, phoneMobileNumber);
}
return cell;
}
ok here is solution
` ABAddressBookRef addressBook=ABAddressBookCreate();
NSArray *allPeople=(NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableArray *holdEachPersonMobileNumbers=[NSMutableArray new];
for (id person in allPeople) {
ABMultiValueRef phoneNumbers = ABRecordCopyValue(( ABRecordRef)(person), kABPersonPhoneProperty);
NSString* mobile=#"";
for (int i=0; i < ABMultiValueGetCount(phoneNumbers); i++) {
mobile = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, i);
NSCharacterSet *trim = [NSCharacterSet characterSetWithCharactersInString:#"#();$&-+"];
mobile = [[mobile componentsSeparatedByCharactersInSet: trim] componentsJoinedByString: #""];
mobile= [mobile stringByReplacingOccurrencesOfString:#"\"" withString:#""];
mobile=[mobile stringByReplacingOccurrencesOfString:#" " withString:#""];
[holdEachPersonMobileNumbers addObject:mobile];
}
}
`
Here holdEachPersonMobileNumbers hold all numbers associated to particular person which u select in address book
put above code in this method
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
Hope u conform this protocol ABPeoplePickerNavigationControllerDelegate
and import this
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
Related
How can we customize the ABPeoplePickerNavigationViewController to display FullName in the first line and email,phone number in the next line. This should not happen on a contact select but should default when the ABPickerController view is loaded.
What I want is the regular functionalities of the ABPeoplePicker.. but the contacts display should have additional information explained above.
I think I would have to extend the ABPeoplePickerNavigationController? Any guidance on this would be greatly appreciated?
If you would want the ABPeoplePicker.... and the addressBook to work together dont quite have a solution.Tried the same thing but finally we spun out a new custom indexed table view. Was quite easy.
if you want an indexed tableView created please have a look at
indexed-ui-tableview
you could then change the following method for having information in multiple lines.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [[[content objectAtIndex:indexPath.section] objectForKey:#"rowValues"]
objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[NSString stringWithFormat:#"%# %# %#", #"someone#gmail.com", #"|",#"123456777777777777777"] ;;
return cell;
}
The data generator can be modified to accomodate your model.
the email etc can be obtained from your model.In the snippet above it is hard coded.You could then easily wire in the search functionality.
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
// assigning control back to the main controller
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
NSString *firstname=(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
Usernametf.text=firstname;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
NSString* phone;
phone = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
phoneNotf.text=phone;
//NSLog(#"%#",phone);
if([address count] > 0)
{
for (NSDictionary *addressDict in address)
{
NSString* countrytf = [addressDict objectForKey:#"Country"];
NSString* streetaddresstf= [addressDict objectForKey:#"Street"];
NSString* citynametf = [addressDict objectForKey:#"City"];
NSString* statenametf = [addressDict objectForKey:#"State"];
NSString* zipcodetf = [addressDict objectForKey:#"ZIP"];
}
CFRelease(addressProperty);
}
// NSMutableDictionary *dict=[[NSMutableDictionary alloc] initWithObjectsAndKeys:firstname,#"FirstName", nil];
//[selectedemailArray addObject:dict];
// NSLog(#"\n array is %#",selectedemailArray);
//[objDatabase insertArray:selectedemailArray forTable:#"EmailList"];
//[objDatabase insertDictionary:dict forTable:#"EmailList"];
// [dict release];
// dict =nil;
// remove the controller
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
return NO;
}
here is whole code where you can get anything from contacts.
let me know it is working or not...
Happy Coding!!!!
I need help with a custom AddressBook (ABPeoplePickerViewController) for iPhone?
I want to have an array with all my contacts, pulling just their name and numbers into the cells of the tableview to display.. Select a few contacts, open Messages and send them a Text/SMS with a custom message..
WhatsApp messenger is an awesome example, if you go to Settings, Tell a Friend, then Message..
I want that look!
It must be custom as I also want the Send and Cancel buttons below, and Name in cell.textLabel and their number in the cell.detailTextLabel in a Subtitle style tableview.
So how do I get their details from addressbook and into my arrays (contactsName, contactsNumber)? Thanks in advance! Here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [contactsName objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [contactsNumber objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissViewControllerAnimated:YES completion:^{ NSLog(#"Message controller has been canceled"); }];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSString *name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *number = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSLog(#"Name: %# Number: %#", name, number);
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}
- (void)openSMScontroller {
MFMessageComposeViewController *smsView = [[MFMessageComposeViewController alloc] init];
smsView.messageComposeDelegate = self;
smsView.recipients = [NSArray arrayWithArray:contactsNumber];
smsView.body = #"Check out this awesome app!";
[self presentModalViewController:smsView animated:YES];
}
you can get what you want from addressbook by below code my friend.!!!!!
happy coding!!!!!!
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
if([address count] > 0)
{
for (NSDictionary *addressDict in address)
{
countrytf.text = [addressDict objectForKey:#"Country"];
streetaddresstf.text = [addressDict objectForKey:#"Street"];
citynametf.text = [addressDict objectForKey:#"City"];
statenametf.text = [addressDict objectForKey:#"State"];
zipcodetf.text = [addressDict objectForKey:#"ZIP"];
}
CFRelease(addressProperty);
}
}
To get phone number...
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString* phone = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
nslog(#"phone:%#",phone);
let me know it is working or not !!!!!!please if it is right then reward it and i know it is right..
Happy Coding
i am having trouble retrieving the last names of my addressbook. I only want to retrieve last names by each letter of the alphabet.
this is the codes i have so far
ABAddressBookRef addressBook = ABAddressBookCreate();
totalPeople = (__bridge_transfer NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSString *aString = #"A";
for(int i =0;i<[totalPeople count];i++){
ABRecordRef thisPerson = (__bridge ABRecordRef)
[totalPeople objectAtIndex:i];
lastName = (__bridge_transfer NSString *) ABRecordCopyValue(thisPerson, kABPersonLastNameProperty);
}
I dont know what to do after, thank you for looking at this.
now it is like this
ABAddressBookRef addressBook = ABAddressBookCreate();
totalPeople = (__bridge_transfer NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSString *aString = #"A";
for(int i =0;i<[totalPeople count];i++){
ABRecordRef thisPerson = (__bridge ABRecordRef)
[totalPeople objectAtIndex:i];
lastName = (__bridge_transfer NSString *) ABRecordCopyValue(thisPerson, kABPersonLastNameProperty);
NSString *firstLetterOfCopiedName = [lastName substringWithRange: NSMakeRange(0,1)];
if ([firstLetterOfCopiedName compare: aString options: NSCaseInsensitiveSearch] == NSOrderedSame) {
//This person's last name matches the string aString
aArray = [[NSArray alloc]initWithObjects:lastName, nil];
}
}
it onlys adds one name to the array, what should i do in order to add it all.
sorry guys, i am fairly new to ios developing!
You could use something like this and store the result in an array or return the result. (Not tested)
NSString *firstLetterOfCopiedName = [lastName substringWithRange: NSMakeRange(0,1)];
if ([firstLetterOfCopiedName compare: aString options: NSCaseInsensitiveSearch] == NSOrderedSame) {
//This person's last name matches the string aString
}
You need to alloc the array outside the loop (otherwise it will only ever contain one object), the array also has to be an NSMutableArray (so it can be modified). Here is an example:
ABAddressBookRef addressBook = ABAddressBookCreate();
totalPeople = (__bridge_transfer NSMutableArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSString *aString = #"A";
//This is the resulting array
NSMutableArray *resultArray = [[NSMutableArray alloc] init];
for(int i =0;i<[totalPeople count];i++){
ABRecordRef thisPerson = (__bridge ABRecordRef)
[totalPeople objectAtIndex:i];
lastName = (__bridge_transfer NSString *) ABRecordCopyValue(thisPerson, kABPersonLastNameProperty);
NSString *firstLetterOfCopiedName = [lastName substringWithRange: NSMakeRange(0,1)];
if ([firstLetterOfCopiedName compare: aString options: NSCaseInsensitiveSearch] == NSOrderedSame) {
//This person's last name matches the string aString
[resultArray addObject: lastName];
}
}
//print contents of array
for(NSString *lastName in resultArray) {
NSLog(#"Last Name: %#", lastName);
}
I want to make an app and want to access the contact numbers directly when i touch/press a particular text field or button and then return to my app with a selected contact number. How can i do this.
You need to add ABPeoplePickerNavigationControllerDelegate delegate in .h file
and in .m file write down below three methods:
#pragma mark People Picker Delegate Methods
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker {
[peoplePicker dismissModalViewControllerAnimated:YES];
[peoplePicker autorelease];
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
return YES;
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)valueID{
ABPropertyType type = ABPersonGetTypeOfProperty(property);
if (type==kABMultiDictionaryPropertyType) {
ABMutableMultiValueRef multi = ABRecordCopyValue(person, property);
CFIndex index = ABMultiValueGetIndexForIdentifier(multi, valueID);
CFDictionaryRef dic = ABMultiValueCopyValueAtIndex(multi, index);
CFStringRef street = CFDictionaryGetValue(dic, kABPersonAddressStreetKey);
NSString* StreetName =(NSString*)street;
streetNameText.text=StreetName;
NSLog(#"StreetName:%#",StreetName);
NSRange range = NSMakeRange (0, 5);
NSLog (#"Beer shortname: %#", [StreetName substringWithRange:range]);
int val = [StreetName intValue];
NSLog(#"StreetName:%d",val);
NSString *newChange = [[NSString alloc] initWithFormat:#"%d", val];
streetNOText.text = newChange;
[newChange release];
CFRelease(dic);
CFRelease(multi);
}
[self dismissModalViewControllerAnimated:YES];
return NO;
}
I am not able to give you the whole code. Following bare the steps :
1. On click to button go to new view which must have tableview
2. In that view get the address book
To get the addressbook
Add these frameworks:
AddressBook,
AddressBookUI
import them in your view
And for getting the contacts from addressbook refer the following tutorial
http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/QuickStart.html#//apple_ref/doc/uid/TP40007744-CH2-SW1
I know this is not the full solution for your question but this link will help you to get the remaining task...Good luck
May this method will help you, just call this method when you want to fetch records from addressbook. n ofcourse add the frameworks AddressBook, AddressBookUI
first create database (as i did if you want you can store it into NSMutable Array instead of database, as per your requirement.)
-(void)fetchRecordsFromAddressBook
{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
//NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
// [arrayContacts removeAllObjects];
[self emptyDataContext];
for (int i = 0; i < nPeople; i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
////////////////// get first name ///////////////////
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
CFStringRef nickName = ABRecordCopyValue(ref, kABPersonNicknameProperty);
CFStringRef middleName = ABRecordCopyValue(ref, kABPersonMiddleNameProperty);
////////////////// get image ///////////////////
// ABMultiValueRef ContactImage = (ABMultiValueRef) ABRecordCopyValue(ref,kABPersonImageFormatThumbnail);
NSData *data=nil;
// NSLog(#"Image Testing is : %#",ref);
if(ABPersonHasImageData(ref))
{
data = [(NSData *) ABPersonCopyImageData(ref) autorelease];
if(data)
{
// NSLog(#"Im Testing is : %#",data);
//image = [[UIImage alloc] initWithData:data];
}
}
// NSLog(#"Image is : %#",ContactImage);
// NSLog(#" Name is : %#",firstName);
////////////////// get email ///////////////////
ABMultiValueRef emails = (ABMultiValueRef) ABRecordCopyValue(ref, kABPersonEmailProperty);
NSString *emailID=#"";
if(ABMultiValueGetCount(emails)>=1)
{
emailID = (NSString *)ABMultiValueCopyValueAtIndex(emails,0);
}
////////////////// get phone number ///////////////////
ABMultiValueRef phones = (ABMultiValueRef) ABRecordCopyValue(ref, kABPersonPhoneProperty);
NSString *phone=#"";
NSString *homeNumber = #"";
NSString *worknumber = #"";
if(ABMultiValueGetCount(phones)>=1)
{
//int ph = [ABMultiValueCopyValueAtIndex(phones, 0) intValue];
phone = (NSString *)ABMultiValueCopyValueAtIndex(phones,0);
}
// NSLog(#"%#",(NSString*)phone);
if(ABMultiValueGetCount(phones)>=2)
{
homeNumber = (NSString *)ABMultiValueCopyValueAtIndex(phones,1);
}
if(ABMultiValueGetCount(phones)>=3)
{
worknumber = (NSString *)ABMultiValueCopyValueAtIndex(phones,2);
}
NSMutableArray *arrayContacts = [[NSMutableArray alloc] init ];
///////////////////////////// insert into array ////////////////////////////
arrayContacts = [CoreDataAPIMethods getObjectsFromContext:#"AllContactData" :#"Index" :NO :self.managedObjectContext];
//////////////////////////// insert Index ///////////////////////////////
int NewEntryID;
if ([arrayContacts count] > 0)
{
AllContactData * Contacdata = [arrayContacts objectAtIndex:0];
NewEntryID = [Contacdata.Index intValue] +1;
}
else
{
NewEntryID = 1;
}
NSString *capitalisedSentence =
[(NSString *)firstName stringByReplacingCharactersInRange:NSMakeRange(0,1)
withString:[[(NSString *)firstName substringToIndex:1] capitalizedString]];
AllContactData *Contactitem=(AllContactData *)[NSEntityDescription insertNewObjectForEntityForName:#"AllContactData" inManagedObjectContext:self.managedObjectContext];
// NSLog(#"%#",capitalisedSentence);
Contactitem.Name = capitalisedSentence;
Contactitem.LastName = (NSString*)lastName;
Contactitem.NickName = (NSString*)nickName;
Contactitem.MiddleName = (NSString*)middleName;
Contactitem.Email=(NSString*)emailID;
phone = [phone stringByReplacingOccurrencesOfString:#"(" withString:#""];
phone = [phone stringByReplacingOccurrencesOfString:#")" withString:#""];
phone = [phone stringByReplacingOccurrencesOfString:#"+" withString:#""];
phone = [phone stringByReplacingOccurrencesOfString:#" " withString:#""];
phone = [phone stringByReplacingOccurrencesOfString:#"-" withString:#""];
NSLog(#"The Replaced String is : %#", phone);
Contactitem.PhoneNumber=(NSString*)phone;
Contactitem.HomeNumber=(NSString*)homeNumber;
Contactitem.WorkNumber=(NSString*)worknumber;
Contactitem.Index = [NSNumber numberWithInt:NewEntryID];
Contactitem.Image = data;
// NSLog(#"Image in databse is : %#",(NSData *)ContactImage);
if(firstName!=nil)
{
CFRelease(firstName);
}
CFRelease(ref);
}
CFRelease(allPeople);
///////////////////////////// save entries ////////////////////////////
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error...
}
}
I'm facing a problem accessing the address book of my iPad 2. In particular I have problems retrieving the email of my contacts. What I want to do is to access the address book, retrieve my contacts and show them in a table view. Everything seems work fine since the name and the surname of the contacts are shown. The problem is with the email property since when I try to retrieve it I get an "EXC_BAD_ACCESS".
The code i wrote to show the tableview record is the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *tableIdentifier = #"tableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
NSUInteger row = [indexPath row];
NSString *firstName = (NSString *)ABRecordCopyValue([contacts objectAtIndex:row], kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue([contacts objectAtIndex:row], kABPersonLastNameProperty);
NSString *name = [[NSString alloc] initWithFormat:#"%# %#", lastName,firstName];
[firstName release];
[lastName release];
cell.textLabel.text = name;
[name release];
NSArray *emails = [[self getEmailForPerson:row] retain];
/*......*/
return cell;
}
While the function to get the email of my contacts is the following:
- (NSArray *)getEmailForPerson:(NSInteger)index{
//Create the array where emails will be stored
NSMutableArray *m = [[[NSMutableArray alloc] init] autorelease];
//Get the email properties
ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty);
//Iterate in the multi-value properties
for (int i=0; i<ABMultiValueGetCount(mails); i++) {
//Get the email
NSString *mail = (NSString *) ABMultiValueCopyValueAtIndex(mails, i);
//Add the email to the array previously initializated
[m addObject:mail];
[mail release];
}
CFRelease(mails);
return m;
}
When I run the debugger after this statement
ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty);
mails seems not initialized since its adress is 0x0 but I cannot understand why.
I hope somebody can help me.
Thanks in advance
ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty);
It works fine in my app.
Check framework & self.contacts.
My app use two frameworks.
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABAddressBook.h>