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