Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contacts Framework. Access to phones ' values

Tags:

ios

contacts

- (void)viewDidLoad {
    [super viewDidLoad];
    self.givenName = [[NSMutableArray alloc]init];

    NSArray *KeysToFetch = @[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey ];
    NSString *containerId = [[[CNContactStore alloc]init]defaultContainerIdentifier];
    NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];

    _contacts = [[[CNContactStore alloc]init]unifiedContactsMatchingPredicate:predicate keysToFetch:KeysToFetch error:nil];

    for (CNContact *c  in _contacts) {

        [_givenName addObject:c.givenName];
        NSLog(@"%@", c.phoneNumbers);
    }
}

Hi, how can I get access to the 'digits' value? when i do a NSLog of 'phoneNumbers' i get this on console:

2015-10-19 12:33:41.423 testContacts[7064:2001002] (
"<CNLabeledValue: 0x7b72eed0: identifier=A73ABAA0-7698-47D7-A2BD-630E04C0C811, label=_$!<Mobile>!$_, value=<CNPhoneNumber: 0x7b734db0: countryCode=us, digits=8885555512>>",
"<CNLabeledValue: 0x7b72eb80: identifier=BC927A1D-AA98-4E67-82A9-BB5AD09A6CAE, label=_$!<Home>!$_, value=<CNPhoneNumber: 0x7b72ecd0: countryCode=us, digits=8885551212>>"
like image 331
jescabias Avatar asked Nov 16 '25 04:11

jescabias


1 Answers

If the phone number is localized with phone characters like 1 (234) 456-78, stringValue returns exactly that string.

To obtain the digits, the correct code (in Swift) is

(contact.phoneNumbers[0].value as! CNPhoneNumber).valueForKey("digits") as! String
like image 162
ZadrackSaria Avatar answered Nov 18 '25 21:11

ZadrackSaria



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!