0

I have an app which gets users address book first and last name. I have tested in both Simulator and on my own iPhone 4S running iOS 7 with XCode 5 and it works and runs fine.

Lately some international users have been complaining that my app keeps crashing on them. Fortunately I was able to download the crash log from iTunes, and when I symbolicate it I found the app crashed on at least one users at the following step. I asked the user what's so special about their addressbook and he mentioned that he has some names in English, Hebrew. My question is why would it crash at that line? Is it that CFStringRef is a sensative variable and I should use something else instead? I cannot for the life of me figure it out.

CRASH LOG:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000005152dca8
Triggered by Thread:  0

Thread 0 Crashed:
0   AppSupport 0x3237642d CPRecordGetProperty + 21
1   AppSupport 0x323765c1 CPRecordCopyProperty + 9
2   AddressBook 0x2e154457 ABRecordCopyValueUnfiltered + 79
3   AddressBook 0x2e1542f7 ABRecordCopyValue + 79
4   Contacts HD 0x0008a583 -[v1AddressBookTblController getValsForTable] (v1AddressBookTblController.m:147)

CODE:

- (IBAction) getValsForTable
{

    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);

    ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
    CFArrayRef allPeopleArray;


    allPeopleArray = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByLastName);


    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

    //NSLog(@"Start LOOP");
    for (int i=0; i<nPeople; i++)
    {
        //NSLog(@"Inside Loop %i", i);

        ABRecordRef ref = CFArrayGetValueAtIndex(allPeopleArray, i);

        //CRASH HAPPENS HERE
        CFStringRef firstNameStr = ABRecordCopyValue(ref, kABPersonFirstNameProperty); 

...

Tried using non-ASCII first name in addressbook and the app still works fine.

enter image description here

Larme
  • 24,190
  • 6
  • 51
  • 81
Sam B
  • 27,273
  • 15
  • 84
  • 121
  • thread crash ... app closes on those users. I cannot reproduce that on my actual device or simulator – Sam B Jul 07 '14 at 19:24
  • In the crash report, what does it show for "Exception Type"? Any other helpful details in the crash log? – rmaddy Jul 07 '14 at 19:26
  • Have you tried various name combinations while testing? Like Last name but no First name, middle name but no last and first names, no names at all and phone only? – Eugene Jul 07 '14 at 19:27
  • Yes, I created 3 records, each with first or last or middle names only. Works fine on my iPhone. Exception type was EXC_BAD_ACCESS (SIGSEGV). The only thing I can think of is adding a name with international non-ascii characters in it. But don't know how to add that kind of name in Simulator. Might have to change my keyboard – Sam B Jul 07 '14 at 19:30

1 Answers1

3

I had the same error, the problem is that:

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName);

and

CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

are giving a different number of contacts (so in your case nPeople is probably bigger than allPeople, which causes the crash). source doesn't seem to be giving all the contacts in the address book. Changing it to nil solved it for me. Also, to be sure I would do:

nPeople = CFArrayGetCount(allPeople);

The solution is explained by Jokinryou Tsui in this post: ABAddressBookCopyArrayOfAllPeople and ABAddressBookGetPersonCount return different sizes

(This is my first post, so I'm not sure if I broke any rules or followed the right procedure. I hope the answer helps!)

Mufasa
  • 86
  • 4
  • thank you for the suggestion. never in a million years could i have thought that was happening. Let me upload a new binary to itunes and will let you know once the user who experienced the crash tells me that all is well – Sam B Aug 04 '14 at 22:36