Вопрос

I think I need to use ABMultiValueCopyArrayOfAllValues to grab all phone numbers from my ABAddressBookRef reference variable.

(If this is not the correct way to do it, please give me a correct way; ANY way that gives me access to contact phone numbers will do)

What I'd like to do now, is grab my user's contact's phone numbers(preferably their cell) and add that to an array. How do I grab just the numbers and add that to an array?

Any help, suggestions, or advice with this is greatly appreciated in advice, I'm not finding this anywhere.

Thanks.

Это было полезно?

Решение

If I were you, I would use this approach:

NSMutableArray *allPhoneNumbers = @[].mutableCopy;
NSArray *allContact = (__bridge NSArray*)ABAddressBookCopyArrayOfAllPeople(book);
for (id rec in allContacts){
    ABMultiValueRef mvr = ABRecordCopyValue((__bridge ABRecordRef)rec, kABPersonPhoneProperty);
    NSArray *currentNums = (__bridge NSArray*) ABMultiValueCopyArrayOfAllValues(mvr);
    [allPhoneNumbers addObjectsFromArray: currentNums];
}

I have not tested this, but it should work. Tell me if you have any issues.

If you want just one contact's numbers (the above gets every contact), use this code.

ABMultiValueRef mvr = ABRecordCopyValue(yourRecordRef, kABPersonPhoneProperty);
NSArray *currentNums = (__bridge NSArray*) ABMultiValueCopyArrayOfAllValues(mvr);
[allPhoneNumbers addObjectsFromArray: currentNums];

Другие советы

ABMultiValueRef phoneNumbers = ABRecordCopyValue(ref, kABPersonPhoneProperty);    
for(CFIndex j = 0; j < ABMultiValueGetCount(phoneNumbers); j++)    
{  
  CFStringRef phoneNumberRefCF = ABMultiValueCopyValueAtIndex(phoneNumbers, j);  
  CFStringRef locLabelCF = ABMultiValueCopyLabelAtIndex(phoneNumbers, j);  
  NSString *phoneLabelCF =(NSString*) ABAddressBookCopyLocalizedLabel(locLabelCF);  
  NSString *phoneNumberCF = (NSString *)phoneNumberRefCF;  
  CFRelease(phoneNumberRefCF);  
  CFRelease(locLabelCF);  
  NSLog(@"  - %@ (%@)", phoneNumberCF, phoneLabelCF);  
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top