【问题标题】:Read/Parse Data from vCard从 vCard 读取/解析数据
【发布时间】:2013-09-24 08:26:38
【问题描述】:

iOS SDK 中是否有任何框架/库可用于读取/解析 vCard 格式的数据? 我在 NSString 中接收 vcard 格式的数据,我必须解析它。 谷歌了很多,但还没有找到解决方案。

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

【问题讨论】:

    标签: iphone ios objective-c vcf-vcard


    【解决方案1】:

    我确实为你找到了一些解决方案......

    看看下面的链接...

    1)想要现成的示例代码==>Click here

    2) 写入 Vcard==>Click here

    与您相关的代码:

    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) 导入 vCard 示例代码==>Click here

    4) 用于创建自定义解析器 ==> Click here

    【讨论】:

    • @Puneed Kamath 非常感谢详细的回复和参考代码。我用过 vCardImporter。问题是我不想使用通讯录在我的联系人应用程序中保存任何内容。我只想解析并获得这样的所需值。 vCard.FName // 将返回名字 vCard.Phone // 将返回我电话。你知道我该怎么做吗?
    • @TaimurAjmal..希望我现在能带着我的 mac...我可以为你写代码..但部分我可以指导你...检查它==>@987654325 @
    • if([[abc objectAtIndex:1] isEqualToString:@”WORK”]) { }
    【解决方案2】:

    OS X v10.11 和 iOS 9 引入了CNContactVCardSerialization,这使得解析 VCard 变得轻而易举。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2012-09-21
    相关资源
    最近更新 更多