iPhone读电话本

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];

你可能感兴趣的:(iPhone,电话)