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

  • Home
  • SEARCH
  • 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 3350774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:49:40+00:00 2026-05-18T01:49:40+00:00

I have the following code : ABAddressBookRef ab; ab = ABAddressBookCreate(); int len =

  • 0

I have the following code :

ABAddressBookRef ab;
ab = ABAddressBookCreate();
int len = (int) ABAddressBookGetPersonCount(ab);
int i;
for(i = 1; i < (len + 1); i++)
{
  ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab,(ABRecordID) i);
  CFStringRef firstName, lastName;
  firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
  lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
  static char* fallback = "";
  int fbLength = strlen(fallback);
  int firstNameLength = fbLength;
  bool firstNameFallback = true;
  int lastNameLength = fbLength;
  bool lastNameFallback = true;
  if (firstName != NULL)
  {
     firstNameLength = (int) CFStringGetLength(firstName);
     firstNameFallback = false;
  }
  if (lastName != NULL)
  {
     lastNameLength = (int) CFStringGetLength(lastName);
     lastNameFallback = false;
  }
  if (firstNameLength == 0)
  {
    firstNameLength = fbLength;
    firstNameFallback = true;
  }
  if (lastNameLength == 0)
  {
    lastNameLength = fbLength;
    lastNameFallback = true;
  }
  firstNameString = malloc(sizeof(char)*(firstNameLength+1));
  lastNameString = malloc(sizeof(char)*(lastNameLength+1));
  if (firstNameFallback == true)
  {
     strcpy(firstNameString, fallback);
  }
  else
  {
     CFStringGetCString(firstName, firstNameString, 10*CFStringGetLength(firstName), kCFStringEncodingASCII);
  }
  if (lastNameFallback == true)
  {
     strcpy(lastNameString, fallback);
  }
  else
  {
     CFStringGetCString(lastName, lastNameString, 10*CFStringGetLength(lastName), kCFStringEncodingASCII);
  }


   printf("%d.\t%s %s\n", i, firstNameString, lastNameString);
   NSString *fname= [NSString stringWithFormat:@"%s",firstNameString];
   NSString *lname= [NSString stringWithFormat:@"%s",lastNameString];
  [dict setValue:fname forKey:@"fname"];
  [dict setValue:lname forKey:@"lname"];
  [self.arrname addObject:[dict copy]];

if (firstName != NULL)
{
    CFRelease(firstName);
}
if (lastName != NULL)
{
    CFRelease(lastName);
}

free(firstNameString);
free(lastNameString);

}

it working well for first time.

But When i delete record from contact list and then try to add record my App crase at the following statement.

firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);

Can anyone solve this problem ??
Any Idea is greatly 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-18T01:49:40+00:00Added an answer on May 18, 2026 at 1:49 am

    There’s no guarantee that the valid ABRecordID starts at 1 and ends at ABAddressBookGetPersonCount(addressBook). You can’t use the for-loop using ABRecordID.

    Instead, obtain the CFArray containing all the people using ABAddressBookCopyArrayOfAllPeople and iterate on it.

    Another comment is that you shouldn’t use C string; most of the things can be done using the API of CFString and NSString, which supports Unicode out of the box. By getting the C string specifying kCFStringEncodingASCII, you’re basically destroying letters like é or ü, ગુજરાતી or 案. (Note that CFStringGetCString with kCFStringEncodingASCII is quite picky and removes characters not in the ASCII; it doesn’t give you UTF8 representation of the string.) There’re many people whose name contains non-ASCII characters. So, please do learn CFString and NSString methods. Note that a CFStringRef and an NSString* can be freely interchanged.

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

Sidebar

Related Questions

I have a rather unexpected result with the following code: ABAddressBookRef addressBook = ABAddressBookCreate();
I have following code class Test { public: int &ref; int a; Test(int &x)
I have following code #include <stdio.h> #include<ctype.h> typedef struct { int Type; int Type2;
I have following code: typedef int (*t_Function) (int x); t_Function Functions[MAX_FUNCTIONS]; int f(int x)
I have following code snippet in c# List<int> list = new List<int>() { 1,
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from

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.