0
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);

        BOOL isExisted=FALSE;
        for (id record in allContacts){
            ABRecordRef thisContact = (__bridge ABRecordRef)record;

            if(thisContact!=nil){


                if (CFStringCompare(ABRecordCopyCompositeName(thisContact),
                                    ABRecordCopyCompositeName(newPerson), 0) == kCFCompareEqualTo){
                    //The contact already exists!
                    isExisted=YES;
                }
            }

        }

Above is my code to get the contacts and check if that contact is already exist in Addressbook but its getting an error at line if

(CFStringCompare(ABRecordCopyCompositeName(thisContact),
                                        ABRecordCopyCompositeName(newPerson), 0) == kCFCompareEqualTo)

can anyone please help me..

am using ARC Enabled Project

BhavikKama
  • 8,566
  • 12
  • 94
  • 164
  • Check the value of `ABRecordCopyCompositeName(thisContact)`and `ABRecordCopyCompositeName(newPerson)` to see which one is problematic. We don't have any info on `newPerson` could be the culprit. – Larme Mar 19 '15 at 13:43

1 Answers1

0

Hi I had the same issue the problem is to check if your current new person hasn't any nil fields and before making comparison check if thisContact name field is not nil.

This is how i did:

    NSString *firstName = CFBridgingRelease(ABRecordCopyValue(thisContact, kABPersonFirstNameProperty));
    NSString *lastName = CFBridgingRelease(ABRecordCopyValue(thisContact, kABPersonLastNameProperty));

you can check the phone number, email if you want to make a comparison

Constantin Saulenco
  • 2,353
  • 1
  • 22
  • 44