Reputation: 1075
Well, to get phones property with ABAddressBook
, I use a loop.
EDIT : code I've tried :
ABMultiValueRef phones = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty);
for (NSUInteger j = 0; j < ABMultiValueGetCount(phones); j++) {
NSMutableString *phone = [CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, j)) mutableCopy];
if ([phone hasPrefix:@"06"] || [phone hasPrefix:@"07"]){
person.number = phone;
}
But I don't think this is the best option..?
Maybe something like :
if (ABMultiValueRef hasprefix...06 || 07){
person.number = phones
}
When the contact has multiple value of phone numbers, I can count it with ABMultiValueGetCount(phones)
.
Well, now take an example :
The contact « Peter » has got 5 phone numbers in ABAddressBook
(NSLog
phones):
02 35 00 00 00
07 00 00 00 00
+1(919)949-8234
06 00 00 00 00
9009498923
I would like to sort these numbers, and store only ONE in NSString
:
if number begins by 07 —> TAKE IT. (assign to NSString
)
if number begins by 06 —> TAKE IT. (assign to NSString
)
if other number —> Don’t assign.
if they are two phone number : one with 06, one with 07, take the last registered in ABAddressBook
(or if this not possible/too complicated, take the number beginning by 07).
I would like to make this loop for every contact in ABAddressBook
. and every contact has only ONE number (or 0 if numbers don't begin by 06 or 07).
In my example :
Peter has got this number : 07 00 00 00 00
Upvotes: 0
Views: 60
Reputation: 1075
Best answer I've found myself :
ABMultiValueRef phones = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty);
for (NSUInteger j = 0; j < ABMultiValueGetCount(phones); j++)
{
if ([CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, j)) hasPrefix:@"07"]
|| [CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, j)) hasPrefix:@"06"]
||[CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, j)) hasPrefix:@"+33"])
{
}
}
Upvotes: 1