-3

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.

1 Answers1

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);
    }
Community
  • 1
  • 1
Larme
  • 24,190
  • 6
  • 51
  • 81