I am working on Action Extension Objective C. I have successfully created Extension for share recent contact in my Extension. In that I am getting v Card String. How can I get Mobile Number from v Card String. Any help would be appreciated.
Asked
Active
Viewed 713 times
-3
-
`contactsWithData:error:` method of `CNContactVCardSerialization`? – Larme Jan 28 '16 at 10:54
-
Can you please provide some code samples – Paresh Vasoya Jan 28 '16 at 11:54
-
@PareshVasoya The Apple documentation is usually very clear. – dandan78 Jan 28 '16 at 13:55
1 Answers
0
Using contactsWithData:error:
class method of CNContactVCardSerialization
, you can retrieve info from a vCard.
It's from Contacts.framework
, available since iOS9.
For earlier version, you can use AddressBook.framework
. You can read info here.
NSError *errorVCF;
NSArray *allContacts = [CNContactVCardSerialization contactsWithData:[contactStr dataUsingEncoding:NSUTF8StringEncoding] error:&errorVCF];
if (!errorVCF)
{
NSMutableString *results = [[NSMutableString alloc] init];
//NSLog(@"AllContacts: %@", allContacts);
for (CNContact *aContact in allContacts)
{
NSArray *phonesNumbers = [aContact phoneNumbers];
for (CNLabeledValue *aValue in phonesNumbers)
{
CNPhoneNumber *phoneNumber = [aValue value];
[results appendFormat:@"%@ %@\n", [aValue label], [phoneNumber stringValue]];
}
}
NSLog(@"Final: %@", results);
}