语言

Menu
Sites
Language
Store VCard string as Contact

Dear Tizen Geeks,

Hello.

I need to parse a vcard string to store in the Contact db as contact.

There is a native API for VCARD parsing.

I have implemented my code:

    const char *msg = "BEGIN:VCARD\nVERSION:3.0\nN;CHARSET=UTF-8:Hyman;Jeffrey;;;\nFN;CHARSET=UTF-8:Jeffrey Hyman\nTEL;TYPE=VOICE;PREF;CHARSET=UTF-8:123456789\nEMAIL;TYPE=WORK;PREF;CHARSET=UTF-8:user1@domain.com\nNICKNAME;CHARSET=UTF-8:joey ramone\nREV:2015-02-09T07:08:58Z\nEND:VCARD";
	INF("VCard : [%s]", msg);
	contacts_list_h list = NULL;
	contacts_error_e err = CONTACTS_ERROR_NONE;

err = contacts_connect();
	if(err != CONTACTS_ERROR_NONE)
		ERR("contacts_connect Error[ %s ]", get_error_msg_contact(err));
	err = contacts_vcard_parse_to_contacts(msg, &list);
	if( err != CONTACTS_ERROR_NONE)
		ERR("Error[ %s ]", get_error_msg_contact(err));

	contacts_list_destroy(list, true);

	err = contacts_disconnect();
	if(err != CONTACTS_ERROR_NONE)
		ERR("contact_disconnect() is failed(%x)", err);

 

The problem is, if I send different version's (except version 3.0) VCard string to contacts_vcard_parse_to_contacts API, the API can't parse it.

Any idea about this?

Your support is appreciated!

Thanks-

//Mohammad N. Nobi

编辑者为: Mohammad Nur Nobi 07 12月, 2015
查看选择的答案

响应

2 回复
Jongkyu Koo

Hello

vCard APIs based on vCard v3.0 specification.

the APIs make vCard v3.0 and can parse vCard v2.1 and v3.0

What version of vCard did you send to contacts_vcard_parse_to_contacts API?

 

 

Mark as answer
Aneendya Sarker

Hi,
Seems like you are trying to parse a given vCard Stream into a list, and store it into device Contact DB.
Please refer the following points.
 

It is not clear which error is returned from contacts_vcard_parse_to_contacts().

CONTACTS_ERROR_INVALID_PARAMETER or CONTACTS_ERROR_NOT_SUPPORTED are returned if vCard format is wrong.

If vCard format is correct, updating to latest Tizen version may solve this problem.

2. After you call contacts_vcard_parse_to_contacts(msg, &list), you need to use contacts_db_insert_records() to insert it into Contact DB.

int count = 0;
int *ids = NULL;
err = contacts_db_insert_records(list, &ids, &count);

Your modified code should look as below.

const char *msg = "BEGIN:VCARD\nVERSION:3.0\nN;CHARSET=UTF-8:Hyman;Jeffrey;;;\nFN;CHARSET=UTF-8:Jeffrey Hyman\nTEL;TYPE=VOICE;PREF;CHARSET=UTF-8:123456789\nEMAIL;TYPE=WORK;PREF;CHARSET=UTF-8:user1@domain.com\nNICKNAME;CHARSET=UTF-8:joey ramone\nREV:2015-02-09T07:08:58Z\nEND:VCARD";
INF("VCard : [%s]", msg);
contacts_list_h list = NULL;
contacts_error_e err = CONTACTS_ERROR_NONE;
err = contacts_connect();asd
if(err != CONTACTS_ERROR_NONE)
    ERR("contacts_connect Error[ %s ]", get_error_msg_contact(err));
err = contacts_vcard_parse_to_contacts(msg, &list);
if( err != CONTACTS_ERROR_NONE)
    ERR("Error[ %s ]", get_error_msg_contact(err));
// added code block start; insert contact into Contact DB
int count = 0;
int *ids = NULL;
err = contacts_db_insert_records(list, &ids, &count);
if( err != CONTACTS_ERROR_NONE)
    ERR("Error[ %s ]", get_error_msg_contact(err));
// added code block end
err = contacts_list_destroy(list, true);
if( err != CONTACTS_ERROR_NONE)
    ERR("Error[ %s ]", get_error_msg_contact(err));
err = contacts_disconnect();
if(err != CONTACTS_ERROR_NONE)
    ERR("contact_disconnect() is failed(%x)", err);

3. As Jongkyu Koo has mentioned, current vCard parsing is based on vCard version 3.0 specification.
It is backward compatible to ver. 2.1 as well.
 

4. In my test, I was able to import both vCard ver. 2.1 and 3.0 properly. But be noted that ver 4.0 is not properly supported.
I've used the below vCard ver. 2.1 sample.

BEGIN:VCARD
VERSION:2.1
N;CHARSET=utf-8:周;宪
FN;CHARSET=utf-8:周宪
TEL;CELL;VOICE:18573183138
TEL;WORK;VOICE:073188033808
EMAIL;PREF;INTERNET:66426222@qq.com
URL;WORK;CHARSET=utf-8:www.zzyq.cc
TITLE;CHARSET=utf-8:研发总监
ORG;CHARSET=utf-8:北京中周理才信息技术有限公司;
ADR;WORK;PREF;CHARSET=utf-8:;;开福区北辰三角洲 D3区1栋3001;长沙市;;410008;中国
LABEL;WORK;PREF;CHARSET=utf-8:长沙市开福区北辰三角洲 D3区1栋3001, 410008
NOTE;CHARSET=utf-8:中周至尚
NOTE;CHARSET=utf-8:ZINGROW
END:VCARD

If in your case, contacts_vcard_parse_to_contacts() is returning any error, please let us know the error value.
Also let us know the vCard ver. 2.1 stream that you used, which contacts_vcard_parse_to_contacts() API could not parse.