一、在工程中添加AddressBook.framework和AddressBookUI.framework
二、获取通讯录
1、在infterface中定义数组并在init方法中初始化
1 |
NSMutableArray *addressBookTemp; |
3 |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil |
5 |
addressBookTemp = [NSMutableArray array]; |
2、定义一个model,用来存放通讯录中的各个属性
新建一个继承自NSObject的类,在.h中
01 |
@interface TKAddressBook : NSObject {
|
02 |
NSInteger sectionNumber; |
08 |
@property NSInteger sectionNumber; |
09 |
@property NSInteger recordID; |
10 |
@property (nonatomic, retain) NSString *name; |
11 |
@property (nonatomic, retain) NSString *email; |
12 |
@property (nonatomic, retain) NSString *tel; |
在.m文件中进行synthesize
1 |
@implementation TKAddressBook |
2 |
@synthesize name, email, tel, recordID, sectionNumber; |
3、获取联系人
在iOS6之后,获取通讯录需要获得权限
02 |
ABAddressBookRef addressBooks = nil; |
04 |
if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) |