官方地址:https://github.com/heardrwt/RHAddressBook
1.安装配置:http://rheard.com/blog/using-static-ios-libraries/
主要步骤
http://rheard.com/skitch/UsingStaticLibraries1-20121104-223027.png
http://rheard.com/skitch/UsingStaticLibraries2-20121104-223532.png
http://rheard.com/skitch/UsingStaticLibraries4-20121104-224413.png
上代码:
// // ViewController.m #import "ViewController.h" #import <RHAddressBook/AddressBook.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // 1.获取授权状态 RHAuthorizationStatus status = [RHAddressBook authorizationStatus]; // 2.判断如果是未授权,则直接返回 if (status != RHAuthorizationStatusAuthorized) return; // 3.创建通信录 RHAddressBook *addressBook = [[RHAddressBook alloc] init]; // 4.获取所有的联系人 NSArray *peopleArray = addressBook.people; // 5.遍历所有的联系人 for (RHPerson *person in peopleArray) { // 6.获取联系人的姓名 NSLog(@"%@ %@", person.firstName, person.lastName); // 7.获取电话号码 RHMultiValue *phones = person.phoneNumbers; for (int i = 0; i < phones.count; i++) { // 8.获取电话号码和对应的Label NSString *phoneLabel = [phones labelAtIndex:i]; NSString *phoneValue = [phones valueAtIndex:i]; NSLog(@"%@ %@", phoneLabel, phoneValue); } } } @end
时间: 2024-10-09 06:49:20