首页 > 代码库 > 调用通讯录代码,由于本人新手,写此日志记录
调用通讯录代码,由于本人新手,写此日志记录
在.h里写代理协议
,ABPeoplePickerNavigationControllerDelegate
在.m里的viewload(哪里需要调用写在哪里)写这段代码,
ABPeoplePickerNavigationController * picker = [[ABPeoplePickerNavigationController alloc] init];
[picker setPeoplePickerDelegate:self];
[self presentViewController:picker animated:YES completion:nil];
实现代理方法
#pragma ABPeoplePickerNavigationController delegate
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
return YES;
}
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
if(property == kABPersonPhoneProperty) {
ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, property);
int index = ABMultiValueGetIndexForIdentifier(phoneMulti,identifier);
NSString *phone = (NSString*)CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneMulti, index));
kABPersonFirstNameProperty));
NSString * str = [phone stringByReplacingOccurrencesOfString:@"-" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"+86" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"(" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@")" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
[_tfPhoneCode setText:str];
CFRelease(phoneMulti);//C对象的释放
[peoplePicker dismissViewControllerAnimated:YES completion:nil];
}
return NO;
}
调用通讯录代码,由于本人新手,写此日志记录