Read/Parse Data from vCard

2019-03-22 01:49发布

Is there any framework/library available in iOS SDK to read/parse data in vCard format? I am receiving data in a vcard format in a NSString and I have to parse it. Googled a lot, but couldn't find solution yet.

BEGIN:VCARD
VERSION:2.1
N:LastName;FirstName;MiddleName;Prefix;Sufix
ADR;TYPE=HOME: postbox;street2;street1;city;state;zip;country
BDAY:2010-08-19
END:VCARD

2条回答
Anthone
2楼-- · 2019-03-22 02:48

OS X v10.11 and iOS 9 introduces CNContactVCardSerialization which makes parsing a VCard a breeze.

查看更多
爷、活的狠高调
3楼-- · 2019-03-22 02:52

I did found some solutions for you...

Have a look at the following links...

1) Want ready made sample code==>Click here

2) Writing to Vcard==>Click here

Code Relevent to you:

ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book record 
ABRecordRef person = ABPersonCreate(); // create a person  

NSString *phone = @"0123456789"; // the phone number to add  

//Phone number is a list of phone number, so create a multivalue  
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty); 
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,phone,kABPersonPhoneMobileLabel, NULL);

ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil); // first name of the new person 
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil); // his last name 
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, &anError); // set the phone number property 
ABAddressBookAddRecord(addressBook, person, nil); //add the new person to the record

ABRecordRef group = ABGroupCreate(); //create a group 
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error); // set group's name 
ABGroupAddMember(group, person, &error); // add the person to the group         
ABAddressBookAddRecord(addressBook, group, &error); // add the group   

ABAddressBookSave(addressBook, nil); //save the record  

CFRelease(person); // relase the ABRecordRef  variable 

3) Importing vCard sample code==>Click here

4) For creating custom parser ==> Click here

查看更多
登录 后发表回答