这是我访问地址簿的方式: ABAddressBookRef addressBook = ABAddressBookCreate();NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);BOOL 发现 = 否;NSString *名称;int i = 0;while (!found) {//这里我打印了所有的联系信息、姓名和电话号码ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);NSLog(@"el telf: %@ y nombre %@",tempPhone2, [NSString stringWithFormat:@"%@ %@",ABRecordCopyValue(person, kABPersonFirstNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) : @"",ABRecordCopyValue(person, kABPersonLastNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) : @""]);if([[key objectForKey:@"phone"] isEqualToString:tempPhone2]){找到 = 是;}}知道为什么我不访问地址簿中的所有联系人吗?最奇怪的是,当我使用 ABPeoplePickerNavigationController 时,会出现那些丢失的联系人. 解决方案 请尝试以下操作.ABAddressBookRef lAddressBook = ABAddressBookCreate();CFArrayRef lRawAddressBookEntries =ABAddressBookCopyArrayOfAllPeople(lAddressBook);CFIndex lTotalContactsCount = ABAddressBookGetPersonCount(lAddressBook);for (CFIndex i = 0; i < lTotalContactsCount; i++) {ABRecordRef lRef = CFArrayGetValueAtIndex(lRawAddressBookEntries, i);ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(lRef, kABPersonPhoneProperty);NSArray* phoneNumbers1 = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);CFRelease(phoneNumberProperty);//对电话号码做任何你想做的事if(phoneNumbers1 && [phoneNumbers1 isKindOfClass:[NSArray 类]]) {for(NSString *stringPhoneNUMber in phoneNumbers1) {if([stringPhoneNUMber isEqualToString:tempPhone2]){找到 = 是;}}}}Im trying to find a phone number in the address book from my app and I was surprised not to find it.The thing is that I've printed all the numbers of my address book in the console accessed by my app and strangely some of the contacts are missing, I was comparing the output with my address book, it's only few, but still.This is how Im accesing the AddressBook: ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook); BOOL found = NO; NSString *name; int i = 0; while (!found) {//Here I print all the contact info, name and phone number ABRecordRef person = (ABRecordRef)[people objectAtIndex:i]; ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty); NSLog(@"el telf: %@ y nombre %@",tempPhone2, [NSString stringWithFormat:@"%@ %@",ABRecordCopyValue(person, kABPersonFirstNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) : @"",ABRecordCopyValue(person, kABPersonLastNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) : @""]); if([[key objectForKey:@"phone"] isEqualToString:tempPhone2]){ found = YES; } }Any idea why Im not accesing all the contacts in my Address Book?[EDIT]Weirdest thing is that when I use ABPeoplePickerNavigationController those missing contacts appear. 解决方案 Please try the below. ABAddressBookRef lAddressBook = ABAddressBookCreate();CFArrayRef lRawAddressBookEntries =ABAddressBookCopyArrayOfAllPeople(lAddressBook);CFIndex lTotalContactsCount = ABAddressBookGetPersonCount(lAddressBook);for (CFIndex i = 0; i < lTotalContactsCount; i++) { ABRecordRef lRef = CFArrayGetValueAtIndex(lRawAddressBookEntries, i); ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(lRef, kABPersonPhoneProperty); NSArray* phoneNumbers1 = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty); CFRelease(phoneNumberProperty); // Do whatever you want with the phone numbers if(phoneNumbers1 && [phoneNumbers1 isKindOfClass:[NSArray class]]) { for(NSString *stringPhoneNUmber in phoneNumbers1) { if([stringPhoneNUmber isEqualToString:tempPhone2]){ found = YES; } } }} 这篇关于ABAddressBookCopyArrayOfAllPeople 中缺少联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 19:54