문제

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