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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:43:14+00:00 2026-05-27T13:43:14+00:00

Some of our app store users are reporting a crash while searching their address

  • 0

Some of our app store users are reporting a crash while searching their address book.
I’m pretty lost here cause I can’t reproduce this issue.

enter image description here

Is there anything wrong with how I’m querying the address book ? Thanks!!

+ (NSDictionary *) scanAddressBook
{
    #if TARGET_OS_IPHONE
    NSUInteger i;
    CFIndex index;

    ABAddressBookRef addressBook = ABAddressBookCreate();
    NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);

    if ( people==nil || (people && ([people count] == 0)))
    {
        TRACE_LOG(@"scanAddressBook ", @"NO ADDRESS BOOK ENTRIES TO SCAN");
        if(people) [people release];
        CFRelease(addressBook);
        return nil;
    }

    NSMutableArray *numbersArray = [NSMutableArray new];
    NSMutableArray *mailsArray = [NSMutableArray new];

    for ( i=0; i<[people count]; i++ )
    {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

        ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];

        NSMutableDictionary *phoneDictionary = [NSMutableDictionary new];

        CFStringRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
        CFStringRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);

        NSString* log =[NSString stringWithFormat:@"-----CONTACT ENTRY -> %@ : %@", firstName, lastName ];
        TRACE_LOG(@"scanAddressBook",log);


        NSString *userName = @"NoName";
        if (firstName && lastName)
            userName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
        else if (firstName)
            userName = [NSString stringWithFormat:@"%@", firstName];
        else if (lastName)
            userName = [NSString stringWithFormat:@"%@", lastName];

        if(firstName) CFRelease(firstName);
        if(lastName) CFRelease(lastName);
        //
        // Phone Numbers
        //
        ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
        CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers );

        for ( index=0; index<phoneNumberCount; index++ )
        {
            CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, index);
            CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, index);
            CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );    
            // converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"
            // Find the ones you want here
            //

            NSString* log =[NSString stringWithFormat:@"-----PHONE ENTRY -> %@ : %@", phoneNumberLocalizedLabel, phoneNumberValue ];
            TRACE_LOG(@"scanAddressBook",log);

            if (![NetworkingUtils validatePhoneNumber:(NSString *)phoneNumberValue]) {
                NSLog(@"invalid phone number: %@",phoneNumberValue);
                CFRelease(phoneNumberLocalizedLabel);
                CFRelease(phoneNumberLabel);
                CFRelease(phoneNumberValue);
                continue;
            }

            [phoneDictionary setObject:(NSString *)phoneNumberValue forKey:InviteUserDataNumberKeyID];
            [phoneDictionary setObject:(NSString *)phoneNumberLocalizedLabel forKey:InviteUserDataNumberTypeKeyID];
            [phoneDictionary setObject:(NSString *)userName forKey:InviteUserDataNameTypeKeyID];

            CFRelease(phoneNumberLocalizedLabel);
            CFRelease(phoneNumberLabel);
            CFRelease(phoneNumberValue);
            NSMutableDictionary *copyPhoneDict = [phoneDictionary copy];
            [numbersArray addObject:copyPhoneDict];
            [copyPhoneDict release];
        }
        CFRelease(phoneNumbers);
        [phoneDictionary release];

        NSMutableDictionary *mailDictionary = [NSMutableDictionary new];
        ABMutableMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
        CFIndex mailsNumberCount = ABMultiValueGetCount( emails );
        for ( index=0; index < mailsNumberCount; index++ )
        {
            CFStringRef emailValue = ABMultiValueCopyValueAtIndex( emails,index);
            // converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"
            // Find the ones you want here
            //
            NSString* log =[NSString stringWithFormat:@"-----EMAIL ENTRY -> : %@", emailValue ];
            TRACE_LOG(@"scanAddressBook",log);



            if (![NetworkingUtils validateEmail:(NSString *)emailValue]) {
                NSLog(@"invalid email address: %@",(NSString *)emailValue);
                if (emailValue) {
                    CFRelease(emailValue);
                }
                continue;
            }

            [mailDictionary setObject:(NSString *)emailValue forKey:InviteUserDataMailKeyID];
            [mailDictionary setObject:(NSString *)@"email" forKey:InviteUserDataMailTypeKeyID];
            [mailDictionary setObject:(NSString *)userName forKey:InviteUserDataMailOwnerKeyID];

            if (emailValue) {
                CFRelease(emailValue);
            }

            NSMutableDictionary *copyMailDict = [mailDictionary copy];
            [mailsArray addObject:copyMailDict];
            [copyMailDict release];
        }
        if(emails) CFRelease(emails);
        [mailDictionary release];


        [pool drain];
    }

    NSString *countryCode = [[NSUserDefaults standardUserDefaults] objectForKey:RequestUserCountryCodeKeyID];
    if (!countryCode) {
        NSLocale *locale = [NSLocale currentLocale];
        NSString *aCode = [locale objectForKey: NSLocaleCountryCode];
        countryCode = [[NetworkingUtils codesByCountryCode] objectForKey:aCode];
    }

    NSDictionary *aDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [[numbersArray copy] autorelease], InviteUsersNumbersArrayKeyID, 
                                 [[mailsArray copy] autorelease], InviteUsersMailsArrayKeyID,
                                 countryCode, RequestUserCountryCodeKeyID, nil];

    [numbersArray release];
    [mailsArray release];

    [people release];
    CFRelease(addressBook);

    return aDictionary;
#else 
    return nil ;
#endif
}
  • 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-27T13:43:15+00:00Added an answer on May 27, 2026 at 1:43 pm

    CFRelease() will crash if you provide a NULL value. I see most of your CFRelease() calls do check for NULL, but not all of them.

    Most likely one of these is triggering the crash?

    I’m not very familiar with ABAddressBook, so don’t know in what situations they would return NULL.

    On a related note, Objective-C’s -release method does not crash on nil, so you may as well change: if(people) [people release]; to just [people release]; as all methods in Objective-C will silently do nothing if sent to a nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our company wants to offer a plugin gallery or app store where users of
I added some simple WatiN tests to our app today to check that a
We are experiencing some slowdowns on our web-app deployed on a Tomcat 5.5.17 running
Our app supports different browser version from IE to Firefox to Chrome. Now, some
I've been tasked with creating some shortcuts to the desktop when our app installs.
Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some
in our web-app project, we include some jar files. For patching some issues of
For some reason every 3-5 days our web app loses the ability to open
We built an app for a client some time back, signed it with our
Some of our FogBugz users experience that the Screenshot tool does not start-up automatically

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.