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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:53:14+00:00 2026-06-04T15:53:14+00:00

I have the following method for getting the AddressBook contacts: – (void) scanAddressBook {

  • 0

I have the following method for getting the AddressBook contacts:

- (void) scanAddressBook
{

NSUInteger i;
NSUInteger k;

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

if ( people==nil )
{
    NSLog(@"NO ADDRESS BOOK ENTRIES TO SCAN");
    CFRelease(addressBook);
    return;
}

for ( i=0; i<[people count]; i++ )
{
    ABRecordRef person = (__bridge ABRecordRef)[people objectAtIndex:i];
    NSNumber *recordID = [NSNumber numberWithUnsignedInt:ABRecordGetRecordID(person)];

    ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString *name = [NSString stringWithFormat:@"%@ %@",
                      (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty),
                      (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty)];



    CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers );
    NSMutableArray *arrPhoneNumbers = [[NSMutableArray alloc] initWithCapacity:phoneNumberCount];

    for ( k=0; k<phoneNumberCount; k++ )
    {
        CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, k );
        NSString *phoneNumberValue = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex( phoneNumbers, k );
        CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );


        [arrPhoneNumbers addObject:phoneNumberValue];

        CFRelease(phoneNumberLocalizedLabel);
        CFRelease(phoneNumberLabel);
    }

    NSMutableDictionary *dictPerson = [[NSMutableDictionary alloc] init];
    [dictPerson setObject:name forKey:@"contactName"];
    [dictPerson setObject:arrPhoneNumbers  forKey:@"phoneNumbers"];
    [dictPerson setObject:recordID forKey:@"recordID"];

    [arrABFriends addObject:dictPerson];
}

CFRelease(addressBook);
}

Later on, in the next view, I have an option to delete the selected record & this is how it looks like:

-(IBAction) removeContactFromAB
{
ABAddressBookRef addressBook; 
CFErrorRef error = NULL; 
addressBook = ABAddressBookCreate(); //
CFRetain(addressBook);
ABRecordID recordID = (ABRecordID)[[personToDump objectForKey:@"recordID"] integerValue];
NSLog(@"recordID: %d", recordID);
//    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook,(ABRecordID)recordID);
ABRecordRef person = ABAddressBookGetGroupWithRecordID(addressBook, recordID);
//fullName.text = (NSString *)ABRecordCopyCompositeName((ABRecordRef)person);

ABAddressBookRemoveRecord( addressBook, person, &error );

if(error !=NULL)
{
    UIAlertView    *alert =[[UIAlertView alloc] initWithTitle:@"error" message:@"deleting" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"OK",nil];
    [alert show];        
}

ABAddressBookSave(addressBook, &error);
NSLog(@"ERROR: %@", &error);
CFRelease(addressBook);

}

I tried to pass the ABRecordRef & ABRecordID to the next view but in both cases I had EXC_BAD_ACCESS on ABAddressBookRemoveRecord( addressBook, person, &error ).

  • 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-06-04T15:53:16+00:00Added an answer on June 4, 2026 at 3:53 pm

    The problem was that I was trying to retrieve the reference from a group with an ID from a reference & I was getting nil as a reference & later trying to find the record with the reference nil. That’s where my App was giving EXC_BAD_ACCESS.

    So instead of:

    ABRecordRef person = ABAddressBookGetGroupWithRecordID(addressBook, recordID);
    

    There should be:

    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two methods for getting data from my database: - (void)
I have the following method public static void SerializeToXMLFile(Object obj,Type type, string fileName) {
i have the following method in a usercontrol protected override void Render(HtmlTextWriter writer) {
I have the following method it creates a generic list recursively. I'm getting some
I have the following method in my app : - (void) loadModel { //
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have following method which I am using to load ActiveX control dynamically, Dim
I have the following method: private JobCard PopulateObject(JobCard jc, DataRow dataRow) { PropertyInfo[] proplist
I have the following method that is replacing a pound sign from the file
I have the following method that is supposed to be a generic Save to

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.