- (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>>"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With