在Objective-C中获取iPhone的联系人列表

时间:2014-06-02 09:25:17

标签: contacts

我想在不使用iOS Navigation Picker的情况下获取我的iPhone联系人列表。 这是我写的代码......但是它没有用,你知道为什么吗?

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
CFArrayRef allPeopleRef = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, nil, kABPersonSortByFirstName);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

for(int i=0; i<nPeople; i++){
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeopleRef, i );
    CFStringRef tmpStringRef = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    NSLog(@"FirstName: %@", (__bridge NSString *)tmpStringRef);
    CFRelease(tmpStringRef);
}

CFRelease(allPeopleRef);
CFRelease(addressBook);

0 个答案:

没有答案