在Build Phases的Link Binary With 中添加俩个框架框架:AddressBook、AddressBookUI
在类中导入这样俩个头文件#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
遵守协议ABPeoplePickerNavigationControllerDelegate
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.peoplePickerDelegate =
self
;
[
self
presentViewController:peoplePicker animated:
YES
completion:
nil
];
#pragma mark - ABPeoplePickerNavigationControllerDelegate协议方法
-(
BOOL
)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
CFStringRef telValue = ABMultiValueCopyValueAtIndex(valuesRef,index);
CFStringRef anFullName = ABRecordCopyCompositeName(person);
[
self
dismissViewControllerAnimated:
YES
completion:^{
NSLog
(@
"name %@,phone %@"
,anFullName,(__bridge
NSString
*)telValue);
NSLog
(@
"%@"
,[(__bridge
NSString
*)telValue stringByReplacingOccurrencesOfString:@
"-"
withString:@
""
]);
}];
[
self
dismissViewControllerAnimated:
YES
completion:
nil
];
return
NO
;
}
-(
void
)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[
self
dismissViewControllerAnimated:
YES
completion:
nil
];
}