Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 336771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:16:25+00:00 2026-05-12T10:16:25+00:00

I am creating a lookup table mapping contact phone numbers to their corresponding ABRecordRef

  • 0

I am creating a lookup table mapping contact phone numbers to their corresponding ABRecordRef (I need this so I can efficiently look up contact names and photos based on the phone number a user has dialed).

Unfortunately, for 500 contacts it takes around 4 seconds to loop through all the contacts and create my lookup table, which makes my application load much too slowly.

Has anybody else seen problems like this or have any suggested workarounds?

I am testing on a 3G iPhone running OS V3.0. The project is built for target ‘Device 2.1’.

Here is the code:

ABAddressBookRef lAddressBook = ABAddressBookCreate();

CFArrayRef lRawAddressBookEntries =
                           ABAddressBookCopyArrayOfAllPeople(lAddressBook);

static NSMutableDictionary sCustomAddressBookPersonRefs =
                       [[NSMutableDictionary alloc] initWithCapacity:1000];

CFIndex lTotalContactsCount = ABAddressBookGetPersonCount(lAddressBook);

/*************************************************************************/
/* Loop through all the contacts storing a pointer to the address book   */
/* entry for each phone number.                                          */
/*************************************************************************/
for (CFIndex i = 0; i < lTotalContactsCount; i++)
{
  ABRecordRef lRef = CFArrayGetValueAtIndex(lRawAddressBookEntries, i);

  ABMultiValueRef lPhoneNumbers = ABRecordCopyValue(lRef,
                                                    kABPersonPhoneProperty);

  CFIndex lContactPhoneNumberCount = ABMultiValueGetCount(lPhoneNumbers);

  /***********************************************************************/
  /* Loop through all the phone numbers available for this contact.      */
  /***********************************************************************/
  for (int j = 0; j < lContactPhoneNumberCount; j++)
  {
    /*********************************************************************/
    /* Get the next phone number and remove the formatting.              */
    /*********************************************************************/
    CFStringRef lPhoneNumber =
      ABMultiValueCopyValueAtIndex(lPhoneNumbers, j);

    [sCustomAddressBookPersonRefs setValue:(id)lRef
                                    forKey:(NSString *)lPhoneNumber];

    CFRelease(lPhoneNumber);
  }      

  CFRelease(lRef);
  CFRelease(lPhoneNumbers);
}

CFRelease(lRawAddressBookEntries);

The first part of the code before the for loop only takes 0.2 to 0.75 secs to run (including the ABAddressBookCopyArrayOfAllPeople).

There was only one NSLog line in the outer for loop initially, but I preprocessed that out before testing on the Device.

After seeing the problem I put NSLog lines between every line of code and none of the lines seemed to cause significantly longer delays than others. With all those trace lines in it takes ~50 secs to create the lookup table, and each line takes about 0.01 second to output, with the occasional 0.1 to 0.2 secs delay (not the same line of code each time).

Any ideas would be appreciated!

I’m pretty confident no memory management mistakes are present as I’ve run the Leaks checker. There also does not appear to be any way to lookup a contact individually based on its phone number.

(2nd Nov 2009) I have now raised bugs with Apple for this issue:
-Bug ID# 7357996 (Performance) – ABAddressBook SDK APIs have terrible performance
-Bug ID# 7357980 (Enhancement) – ABAddressBook provides no way to lookup contact based on phone number

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:16:25+00:00Added an answer on May 12, 2026 at 10:16 am

    If you cannot optimize the routinue, you can also fork a new thread for the loading, then the app can continue to load and be responsive for the user.

    [NSThread detachNewThreadSelector:@selector(_loadContactsInAnotherThread:) toTarget:self withObject:self];
    
    -(void)loadContactsInAnotherThread:(void *)obj
    {
         NSLog("Do time intensive stuff here.");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a lookup table in C When I define this: typedef struct {
Hi I am creating a reverse phone number look up in my database. I
I want to learn about mapping functions in c/c++ in general so this is
I have a site which allows users to make changes to content. How can
I'm looking into doing some development for the Azure platform. I don't need the
I am creating a webpage with PHP/MySQL, and each page is in its own
I'm trying to figure out the best way to calculate a value that is
We have 2 tables. One holds measurements, the other one holds timestamps (one for
I usually create a solution folder in Visual Studio and put my DB scripts
I've done a chunk of work to retrieve some data from a web service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.