0

I am using the following code to retrieve the user's phone numbers from the address book

ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);

//EXC_BAD_ACCESS error if a user does not have phone number stored in the address book
CFStringRef pNumber = ABMultiValueCopyValueAtIndex(phones,0);

NSString *phoneNumber = [NSString stringWithFormat:@"%@", (NSString *)pNumber]

The issue arises when the user does not have a phone number in the address book, resulting in the error 'EXC_BAD_ACCESS' error. My question is how can I check if for that user, a phone number exists? And only proceed to access the value only if it exists?

Zhen
  • 12,361
  • 38
  • 122
  • 199

1 Answers1

2

How to check the number of phone numbers.

ABMultiValueGetCount(ABRecordCopyValue(aPerson, kABPersonPhoneProperty));
ChangUZ
  • 5,380
  • 10
  • 46
  • 64