1

I have done the following to get record for user info from address book.

- (ABRecordRef)findRecordNSString *)phoneNumber
{
if (phoneNumber == nil)
return nil;
ABAddressBookRef addressBook = ABAddressBookCreate();

CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);

CFIndex n = ABAddressBookGetPersonCount(addressBook);

ABRecordRef record;

//NSLog(@"The Record : %d", record);

int count = 0;

for( int i = 0 ; i < n ; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);

ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{

CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);

NSString *newPhoneNumber = (NSString *)phoneNumberRef;



if([newPhoneNumber isEqualToStringhoneNumber])
{
//NSLog(@"Phone Ref: %@", phoneNumberRef);
NSLog(@"Record New: %d", ref);
record = ref;

i=(int)n;
count = 1;
}
CFRelease(phoneNumberRef);
[newPhoneNumber release];
}

}
[addressBook release];
return record;
}

but i am getting an error when I try to open the viewController in ios5 device but it works in simulator and ios 4. the error is

Program received signal: “EXC_BAD_ACCESS”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Can't find dlopen function, so it is not possible to load shared libraries.)

Also after this error if I forcefully clos the app by double tapping home button and then quit manually the app will only show a black screen. Any idea regarding this?

Evgeny
  • 6,533
  • 5
  • 58
  • 64
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256

1 Answers1

0

Just commented the line

CFIndex n = ABAddressBookGetPersonCount(addressBook); 

And replaced with this to get total number of records

CFIndex n = CFArrayGetCount(all);

Because the count is different for all(Array) and for the variable n.

Hope this will help others too.

Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256