Note that there are some explanatory texts on larger screens.

plurals
  1. POIOS AddressBook is not fetching all the phone number from contact list
    text
    copied!<p>I am using <code>Addressbook</code> in my IOS app to fetch the contact name and numbers, but a strange thing is happening that it is showing phone number of some of the contacts.</p> <p>I was hoping it will show all the contact list with phone number.</p> <p>so here is my code to fetch phone numbers:</p> <pre><code>-(void)getAddressbookData { #if __IPHONE_OS_VERSION_MIN_REQUIRED &lt; 60000 ABAddressBookRef addressBook = ABAddressBookCreate(); #else CFErrorRef *error = nil; ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error); #endif NSArray * people; BOOL accessGranted = [self __addressBookAccessStatus:addressBook]; if (accessGranted) { people = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook); // Do whatever you need with thePeople... } CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); NSMutableArray *contactArray = [[NSMutableArray alloc] init]; for (CFIndex i = 0; i &lt; nPeople; i++) { ABRecordRef record = CFArrayGetValueAtIndex((__bridge CFArrayRef)(people), i); NSString *firstName = (__bridge NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty); NSString *lastName = (__bridge NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty); NSString *fullName = nil; if (ABPersonGetCompositeNameFormat() == kABPersonCompositeNameFormatFirstNameFirst) fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName]; else fullName = [NSString stringWithFormat:@"%@, %@", lastName, firstName]; [contactArray addObject:fullName]; // // Phone Numbers // ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(record, kABPersonPhoneProperty); CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers ); NSMutableArray *numbersArray = [[NSMutableArray alloc] init]; for ( CFIndex k=0; k&lt;phoneNumberCount; k++ ) { CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, k ); CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, k ); CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel ); // converts "_$!&lt;Work&gt;!$_" to "work" and "_$!&lt;Mobile&gt;!$_" to "mobile" // Find the ones you want here // // NSLog(@"-----PHONE ENTRY -&gt; name:%@ : %@ : %@", fullName, phoneNumberLocalizedLabel, phoneNumberValue ); [numbersArray addObject:CFBridgingRelease(phoneNumberValue)]; CFRelease(phoneNumberLocalizedLabel); CFRelease(phoneNumberLabel); CFRelease(phoneNumberValue); } // NSLog(@"phone numbers %@", numbersArray); [contactDictionary setObject:numbersArray forKey:fullName]; CFRelease(record); } selectContacts = contactArray; // NSLog(@"dictionary of array %@", contactDictionary); //NSLog(@"contacts count %d", [selectContacts count]); } -(BOOL)__addressBookAccessStatus:(ABAddressBookRef) addressBook { __block BOOL accessGranted = NO; if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6 dispatch_semaphore_t sema = dispatch_semaphore_create(0); ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { accessGranted = granted; dispatch_semaphore_signal(sema); }); dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); // dispatch_release(sema); } else { // we're on iOS 5 or older accessGranted = YES; } return accessGranted; } </code></pre> <p>so numbersArray is blank for some of the contacts I dont know why it is happening.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload