How to check if phone number exists for a particular user in address book
I am using the following code to retrieve the user's phone numbers from the address book
ABMul开发者_运维百科tiValueRef 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?
How to check the number of phone numbers.
ABMultiValueGetCount(ABRecordCopyValue(aPerson, kABPersonPhoneProperty));
精彩评论