现在的位置: 首页 > 综合 > 正文

iPhone读电话本

2013年01月05日 ⁄ 综合 ⁄ 共 695字 ⁄ 字号 评论关闭

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *masterList = [[NSMutableArray alloc] init];
for (int i = 0; i < nPeople; i++) {
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
    CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
    NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lastName];
    CFRelease(firstName);
    CFRelease(lastName);
    [masterList addObject:contactFirstLast];
    [contactFirstLast release];
}
self.list = masterList;
[masterList release];

抱歉!评论已关闭.