1

I want to check if a contact in my user's addressbook a phone number has. If he does, I want to display that name in an UITableView

I've tried to check for phoneNumbers != nil, but that doesn't work. This is my entire code:

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

if(phoneNumbers != nil){
  [_numbers addObject:[NSString stringWithFormat:@"%@", phoneNumbers]];
}
bdv
  • 1,154
  • 2
  • 19
  • 42
  • So, what is phoneNumbers value when the ABRecord doesn't have a phone property? Can't you just check against that value as opposed to nil? – Cooper Buckingham Jul 02 '14 at 17:29
  • Not really, when I log it it says ABMultiValueRef 0x10ab8bf40 with 0 value(s)\n – bdv Jul 02 '14 at 17:31

1 Answers1

4

Use ABMultiValueGetCount to check if phoneNumbers has any values in it.

example based on question:

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

if(ABMultiValueGetCount(phoneNumbers)){
    [_numbers addObject:[NSString stringWithFormat:@"%@", phoneNumbers]];
}
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
Cooper Buckingham
  • 2,503
  • 2
  • 15
  • 23