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 6567983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:24:04+00:00 2026-05-25T14:24:04+00:00

I’ve been having a crash on some user’s iPhones and I finally got someone

  • 0

I’ve been having a crash on some user’s iPhones and I finally got someone who I can replicate the problem with. Here’s the key segment of the code

ABAddressBookRef addressbook = ABAddressBookCreate();
if( addressbook )
{
    //Got this via http://stackoverflow.com/questions/4641229/code-example-for-abaddressbookcopyarrayofallpeopleinsourcewithsortordering
    ABRecordRef source = ABAddressBookCopyDefaultSource(addressbook);
    CFArrayRef sortedPeople = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressbook, source, kABPersonSortByFirstName);
    //Sort them first

    if( sortedPeople )
    {
        CFIndex contactCount = ABAddressBookGetPersonCount(addressbook);

        for( int i = 0; i<contactCount; i++ )
        {
            ABRecordRef ref = CFArrayGetValueAtIndex(sortedPeople, i);
            NSMutableString *fName = [[[NSMutableString alloc] init] autorelease];
            NSMutableString *lName = [[[NSMutableString alloc] init] autorelease];
            NSMutableDictionary *identifiers = [[[NSMutableDictionary alloc]init]autorelease];
            if( ref )
            {
                //Get the user's name first
                NSLog(@"%@ is the reference", ref);
                CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
                if( firstName )
                {
                    NSString *fn = [NSString stringWithFormat:@"%@",firstName];
                    if([fn hasPrefix:@"(null"])
                        [fName appendString:@""];
                    else
                    {
                        [fName appendString:[NSString stringWithFormat:@"%@", firstName]];
                        [fName setString:[fName stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[fName substringToIndex:1]uppercaseString]]];
                    }
                    CFRelease(firstName);
                }
           }
       }
   }
}

Apparently the result of this line of code:
ABRecordRef ref = CFArrayGetValueAtIndex(sortedPeople, i);

Is sometimes coming back as an NSCFType instead of ABPerson. Any idea on how to check the type of the result? I’m trying to prevent this from crashing the user’s phone. Once I get to this line:

 ABRecordCopyValue(ref, kABPersonFirstNameProperty);

I get an EXC_BAD_ACCESS on this line. And it happens when the log file looks like this:

2011-09-11 17:24:31.355 Holler[1345:707] <CPRecord: 0x6642fb0 ABPerson> is the reference
2011-09-11 17:24:31.358 Holler[1345:707] <CPRecord: 0x66431d0 ABPerson> is the reference
2011-09-11 17:24:31.361 Holler[1345:707] <CPRecord: 0x66433b0 ABPerson> is the reference
2011-09-11 17:24:31.365 Holler[1345:707] <CPRecord: 0x6640fd0 ABPerson> is the reference
2011-09-11 17:24:31.369 Holler[1345:707] <CPRecord: 0x6643510 ABPerson> is the reference
2011-09-11 17:24:31.372 Holler[1345:707] __NSCFType is the reference

Any help would be much appreciated!!!

  • 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-25T14:24:05+00:00Added an answer on May 25, 2026 at 2:24 pm

    I’m pretty sure the crash happens because contactCount is set wrong:

    • sortedPeople is set to all people of one source
    • contactCount is set to the count of all people in the address book

    So if you have multiple sources containing people for your address book, the iteration will leave the bounds of sortedPeople. To fix this, replace

    CFIndex contactCount = ABAddressBookGetPersonCount(addressbook);
    

    with

    CFIndex contactCount = CFArrayGetCount(sortedPeople);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string

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.